PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client [duplicate] PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client [duplicate] mysql mysql

PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client [duplicate]


@mohammed, this is usually attributed to the authentication plugin that your mysql database is using.

By default and for some reason, mysql 8 default plugin is auth_socket. Applications will most times expect to log in to your database using a password.

If you have not yet already changed your mysql default authentication plugin, you can do so by:
1. Log in as root to mysql
2. Run this sql command:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_passwordBY 'password';  

Replace 'password' with your root password. In case your application does not log in to your database with the root user, replace the 'root' user in the above command with the user that your application uses.

Digital ocean expounds some more on this here Installing Mysql


You have to change MySQL settings.Edit my.cnf file and put this setting in mysqld section:

[mysqld]default_authentication_plugin= mysql_native_password

Then run following command:

FLUSH PRIVILEGES;

Above command will bring into effect the changes of default authentication mechanism.


I've tried a lot of ways, but only this works for me

thanks for workaround

check your .env

MYSQL_VERSION=latest

then type this command

$ docker-compose exec mysql bash$ mysql -u root -p 

(login as root)

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';ALTER USER 'default'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';

then go to phpmyadmin and login as :

  • host -> mysql
  • user -> root
  • password -> root

hope it help