关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

php 无法连接MySQL8.0 问题

发布时间:2019-09-27 10:42:00

最近升了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



/template/Home/Zkeys/PC/Static