Solving MySQL 5.7 authentication method problems in Laravel
Last week I was setting up al old Laravel project that required MySQL 5.7. I installed DBngin so I could have the legacy MySQL version up and running alongside the modern MySQL 8. Smooth sailing so far, until my Laravel app wanted to connect to the database.
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
It took some googling to find a solution that worked. Most solutions recommended changing the authentication method in MySQL, but this was already configured correctly for me. What I had to do was explicitly configure a socket for MySQL to connect with. I added the following to my .env
file:
DB_SOCKET=/tmp/mysql_3307.sock
Replace 3307
with the port number you configured your MySQL server to run on.