php 无法连接MySQL8.0 问题

发布时间:2021-09-23

  最近升了MySQL8.0 php连不上MySQL8.0了(mysqlnd API 不支持 caching_sha2_password)
MySQL8.0默认是使用caching_sha2_password 加密插件的,我们需要将该插件替换成原来的mysql_native_password 加密插件。www.lu0.com
解决方案
1.添加用户并指定密码插件
在MySQL shell中输入:

  drop user root@%;

  create user root@% identified WITH mysql_native_password BY root;
grant all privileges on *.* to root@% with grant option;
flush privileges;
这种方法兼容新老版本的认证方式
2.直接在mysql配置文件的指定密码插件
[mysqld]
default_authentication_plugin=mysql_native_password
改完配置后记得重启mysqld
参考资料:

  

注册即送1000元现金券