MySQL 8 & Laravel: The server requested authentication method unknown to the client

Mattias Geniar, Tuesday, March 19, 2019

For local development I use Laravel Valet. Recently, the brew packages have updated to MySQL 8 which changed a few things about its user management. One thing I continue to run into is this error when working with existing Laravel applications.

 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

So, here's the fix. You can create a user with the "old" authentication mechanisme, which the MySQL database driver for PHP still expects.

CREATE USER 'ohdear_ci'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ohdear_secret';
GRANT ALL PRIVILEGES ON ohdear_ci.* TO 'ohdear_ci'@'localhost';

If you already have an existing user with permissions on databases, you can modify that user instead.

ALTER USER 'ohdear_ci'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ohdear_secret';

After that, your PHP code can once again connect to MySQL 8.



Hi! My name is Mattias Geniar. 👋 I'm an independent software developer ⌨️ & Linux sysadmin 👨‍💻, a general web geek & public speaker. Currently working on DNS Spy & Oh Dear! Follow me on Twitter as @mattiasgeniar 🐦.

🔥 If you're stuck with a technical problem, I'm available for hire to help you fix it!

Share this post

Did you like this post? Help me share it on social media! Thanks. 🤗

Have feedback?

New comments have been disabled on this blog, existing comments will remain as-is. Want to give feedback? Is there a mistake in the post?

Send me a tweet on @mattiasgeniar!

Comments

asif Wednesday, May 22, 2019 at 11:42 -

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: — MySQL dump 10.16 Distrib 10.1.28-MariaDB, for Win32 (AMD64)
Please Reply Fast.


Derrick Thursday, September 19, 2019 at 08:26 -

Check Config/database.php and .env files if the credentials provided match
(Laravel + MYSQL)