An exception occurred in driver: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

12,589

Solution 1

You have to use legacy style passwords for MySQL 8 and PHP7+:

ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';

Solution 2

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.

Reference Link

Solution 3

You can set the directive in your mysql configuration :

[mysqld]
default_authentication_plugin=mysql_native_password
Share:
12,589
Admin
Author by

Admin

Updated on June 11, 2022

Comments

  • Admin
    Admin almost 2 years

    This error appears in my case in PHP Symfony4 /PDO Doctrine with MySql 8.0.13 Server when I try to connect to Database:

    An exception occurred in driver: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

  • Jamshad Ahmad
    Jamshad Ahmad over 3 years
    I was trying with 'root'@'127.0.0.1' getting error. But then I tried 'root'@'localhost' and it worked fine.
  • Xanlantos
    Xanlantos over 3 years
    Please elaborate why this solution should be used.
  • GregOs
    GregOs over 3 years
    @Xanlantos so you wouldn't have to specify it every time you create / update a user with mysql. It would be set as default.