skip to Main Content

I’ve hosted my laravel app on a digitalocean droplet (Ngnix Ubuntu) . Everything from this side is working well.

I need to test remote access to mysql.

  1. First, from the Droplet’s side, I’ve granted access to mysql by any
    Ip address by this command: sudo ufw allow 3306

  2. To test the remote access, I’ve tried to connect a localhost laravel app to the droplet’s mysql database .

DB_HOST= here I've put the Ip address of the droplet.
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=dbuser
DB_PASSWORD=dbpass
  1. It gives this error :
    SQLSTATE[HY000] [2006] MySQL server has gone away (SQL: select * from 'users' where 'username' = admin limit 1)

I tried to search a lot.. tried some suggestions.. still no solution.

EDIT: This is my.cnf file in /etc/mysql ..
my.cnf

Thanks in advance!

2

Answers


  1. Chosen as BEST ANSWER

    Actually it worked when I made another mysql user and granted this user with any ip the access. See here : Allow all remote connections, MySQL


  2. For Laravel, you do not have to put your droplet IP, you have to put 127.0.0.1 or localhost.

    And for testing remote access (not through Laravel), try it normally (with droplet ip or domain name) and if the errors continue, you will have to bind (in the MySQL config) your droplet local IP (surely it is commented out, it should be something like bind-address, something like that).

    Look at this for more info.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search