mysql8错误:SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
php连接mysql8时报错SQLSTATE[HY000] [2054]...解决方式
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
原因:
因为php不支持mysql8的新特性,
mysql8使用caching_sha2_password作为默认的身份验证插件,
而不再是mysql_native_password
查看方式
phpinfo()
页面查找关键词caching_sha2_password ,如未找到,
修改 MySQL 验证密码方式为 mysql_native_password:
export MYSQL_PWD=secret
mysql --user="root" -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secret';"
mysql --user="root" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;"
mysql --user="root" -e "FLUSH PRIVILEGES;"
或者
直接在mysql配置文件my.ini中修改
[mysqld]
default_authentication_plugin = mysql_native_password
重启mysql
相关文章