PHP with MySQL 8.0+ error: The server requested au

2020-01-23 04:55发布

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] [2054] 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?

8条回答
霸刀☆藐视天下
2楼-- · 2020-01-23 05:12

i've try a lot of ways, but only this work 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

查看更多
ゆ 、 Hurt°
3楼-- · 2020-01-23 05:12

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]

default_authentication_plugin= mysql_native_password

Save the file then log into mysql command line using root user

run command FLUSH PRIVILEGES;

查看更多
欢心
4楼-- · 2020-01-23 05:14
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.

查看更多
够拽才男人
5楼-- · 2020-01-23 05:16

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.

DB_USERNAME=root

Setting this solved my problem.

查看更多
甜甜的少女心
6楼-- · 2020-01-23 05:20

In my.cnf file check below 2 steps.

  • check this value -

    old_passwords=0;

    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.

查看更多
来,给爷笑一个
7楼-- · 2020-01-23 05:21

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.

查看更多
登录 后发表回答