I'm running MySQL version 8 on PHP 7.0.
I'm getting the following error when I try to connect to my database from PHP:
Connect Error: SQLSTATE[HY000]  The server requested authentication method unknown to the client
PHP might show this error
Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in D:\xampp\htdocs\reg\server.php on line 10
How can I fix this problem?
i've try a lot of ways, but only this work for me
thanks for workaround
check your .env
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 :
hope it help
@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_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
Faced the same problem, I was not able to run wordpress docker container with mysql version 8 as its default authentication mechanism is caching_sha2_password instead of mysql_native_password.
In order to fix this problem we must reset default authentication mechanism to mysql_native_password.
Find my.cnf file in your mysql installation, usually on a linux machine it is at the following location - /etc/mysql
Edit my.cnf file and add following line just under heading [mysqld]
Save the file then log into mysql command line using root user
run command FLUSH PRIVILEGES;
I'm using Laravel Lumen to build a small application.
For me it was because I didn't had the DB_USERNAME defined in my .env file.
Setting this solved my problem.
You have to change MySQL settings. Edit my.cnf file and put this setting in mysqld section:
Then run following command:
Above command will bring into effect the changes of default authentication mechanism.
preferences -> mysql -> initialize database -> use legacy password encryption(instead of strong) -> entered same password
as my config.inc.php file, restarted the apache server and it worked. I was still suspicious about it so I stopped the apache and mysql server and started them again and now it's working.
None of the answers here worked for me. What I had to do is:
After that it works fine.
In my.cnf file check below 2 steps.
check this value -
it should be 0.
check this also-
[mysqld] default_authentication_plugin= mysql_native_password Another value to check is to make sure
[mysqld] section should be like this.