MySQL 8.0与phpMyAdmin访问报错#2054,新版本phpMyAdmin已修复
我之前也踩过这个一模一样的坑!当MySQL 8.0搭配旧版本phpMyAdmin时,浏览器访问就会弹出一堆认证相关的错误:
#2054 - The server requested authentication method unknown to the client
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknow...
问题根源
MySQL 8.0 默认启用了caching_sha2_password作为用户认证插件,而旧版本的phpMyAdmin(比如5.0之前的版本)对这个新的认证方式缺乏支持,导致连接时出现兼容性问题。
已验证的最优解决方案:升级phpMyAdmin到新版本
我亲自测试过,将phpMyAdmin升级到5.0.1及以上版本就能完美解决这个问题。新版本的phpMyAdmin已经适配了MySQL 8.0的caching_sha2_password认证机制,不需要额外修改MySQL的配置,直接替换安装包就能正常使用。
可选方案:修改MySQL用户的认证方式(适合不想升级phpMyAdmin的场景)
如果你暂时不想升级phpMyAdmin,也可以通过修改MySQL用户的认证插件为旧版支持的mysql_native_password来绕开问题:
- 登录MySQL命令行:
mysql -u root -p - 执行以下SQL语句修改用户认证方式(替换
your_username和your_password为实际的phpMyAdmin连接用户和密码):ALTER USER 'your_username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password'; FLUSH PRIVILEGES; - 重启MySQL服务后,再访问phpMyAdmin就能正常连接了。
不过更推荐升级phpMyAdmin的方案,毕竟新版本还能带来更多功能优化和安全性更新。
内容的提问来源于stack exchange,提问作者Lucas Noetzold

