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.
-
First, from the Droplet’s side, I’ve granted access to mysql by any
Ip address by this command:sudo ufw allow 3306
-
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
- 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 ..
Thanks in advance!
2
Answers
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
For Laravel, you do not have to put your droplet IP, you have to put
127.0.0.1
orlocalhost
.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.