最近升了MySQL8.0 php连不上MySQL8.0了(mysqlnd API 不支持 caching_sha2_password)
MySQL8.0默认是使用caching_sha2_password 加密插件的,我们需要将该插件替换成原来的mysql_native_password 加密插件。
解决方案
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配置文件my.cnf的指定密码插件
[mysqld]
default_authentication_plugin=mysql_native_password
改完配置后记得重启mysqld
参考资料:
https://stackoverflow.com/questions/49083573/php-7-2-2-mysql-8-0-pdo-gives-authentication-method-unknown-to-the-client-ca
https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/upgrading-from-previous-series.html
Copyright © 2013-2023 . All Rights Reserved. 宵云 版权所有 南通宵云网络科技有限公司
工信部备案:苏ICP备18049042号-2 公安部备案:苏公网安备 32060102320703号
《中华人民共和国增值电信业务经营许可证》经营性ICP/ISP/IDC三证:苏B1.B2-20210805