Skip to content
Advertisement

MySQL8 connection with php7.3 and Symfony 5 does not work

I have a connection problem with a mysql8 database, php7.3 and Symfony 5. The user and the password are correct !

The connection to MySQL8 database must be done from an SSH tunnel

The SSH tunnel is working :

ssh -p [remote_machine_port] -N -L [mysql_tunnel_port]: 127.0.0.1: 3306 -i / [directory] / private_key [username] @ [remote_machine_ip]

MySQL access configuration:

GRANT ALL PRIVILEGES ON 'databasename'.* TO '[user]'@'%' WITH GRANT OPTION;

Doctrine configuration :

DATABASE_URL='mysql://[user]:[password]@127.0.0.1:[port_tunnel_mysql]/[databasename]'

An exception occurred in driver: SQLSTATE [HY000] [1130] Host '127.0.0.1' is not allowed to connect to this MySQL server

I have the same problem with heidiSQL and on the VM

I tried with the Ip of the VM instead of 127.0.0.1

ssh -p [port_machine_distant] -N -L [port_tunnel_mysql]:[ip_machine_vm]:3306 -i /[directory]/private_key [username]@[ip_machine_distant]

Doctrine configuration

DATABASE_URL='mysql://[user]:[password]@[ip_machine_vm]:[port_tunnel_mysql]/[databasename]'

An exception occurred in driver: SQLSTATE [HY000] [2002] Connection refused

However, this setting works with heidiSQL but not with the Symfony application !

Did I forget a setting on the VM or Mysql ?

Advertisement

Answer

127.0.0.1 connection issue : We have created the ‘[user]’@’127.0.0.1’ rights. In MySQL, 127.0.0.1 uses the network and localhost uses the socket.

The message “The server requested authentication method unknown to the client [caching_sha2_password]” was caused because the setting ‘default-authentication-plugin=mysql_native_password’ was created after the creation of the rights. We regenerated the rights, and now everything is working fine.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement