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

Tired of the privacy invasion of the Chrome webbrowser? Worried about the risk of seeing ads everywhere? Give the Brave Browser a try. It supports all the same Chrome extensions, with none of the telemetry. It auto-blocks ads and helps support content creators like me.

Give the Brave browser a try »

Profile image of Mattias Geniar

Mattias Geniar, March 19, 2019

Follow me on Twitter as @mattiasgeniar

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.

Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.