PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /usr/local/php/CreateDB.php on line 5

mysql 安装了最新版本8.0.11后创建用户并授权后,授权的用户连接数据库提示

The server requested authentication method unknown to the client

查阅一些相关的资料后发现是由于新版本的mysql账号密码解锁机制不一致导致的

 mysql 8 升级了密码的验证方式 caching_sha2_password, 之前一直是mysql_native_password方式

解决办法:

方法一:

删除创建的用户和授权,

找到mysql配置文件并加入

 default_authentication_plugin=mysql_native_password

变为原来的验证方式,然后从新创建用户并授权即可

方法二:

mysql -uroot -p

use mysql;

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

然后重启 mysql 即可

mysql.server restart

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐