解决报错 MySQL 8 的 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
使用 PHP 连接 MySQL 8 时:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
在 index.php 中打印:
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;"
推荐文章: