-1

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!

Tarek AS
  • 187
  • 13

2 Answers2

0

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.

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
  • Hello Dear. How will my localhost laravel app know which database it's connected to if I don't put the droplet iP ? – Tarek AS Jun 15 '21 at 19:37
  • You said you wanted to test a remote connection, I am assuming Laravel is local to the database service (MySQL), so if you write `localhost` or `127.0.0.1` it should work. Explain more please, is Laravel and MySQL in the same droplet ? If so, `localhost`. – matiaslauriti Jun 15 '21 at 20:31
  • I have two laravel applications . One in a droplet (1) . And the other is in my localhost (2). So I'm trying to connect (2) with the mysql database hosted on (1) remotely. – Tarek AS Jun 15 '21 at 20:35
  • I understand you are trying to sync remote DB with your local Laravel, I do not recommend to do that, export your DB and then import it in your local – matiaslauriti Jun 15 '21 at 20:52
0

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

Tarek AS
  • 187
  • 13