优先执行ALTER USER 'username'@'host' IDENTIFIED WITH mysql_native_password BY 'password';并FLUSH PRIVILEGES;,或升级phpMyAdmin至5.2+且确保PHP启用openssl及MySQLi≥1.1.0。

MySQL 8.0+ 用户密码认证插件不兼容 phpMyAdmin 怎么办
phpMyAdmin 默认不支持 caching_sha2_password 插件(MySQL 8.0 默认),登录会直接报错 #2054 - The server requested authentication method unknown to the client。这不是 phpMyAdmin 配置问题,而是 MySQL 用户底层认证方式不被客户端识别。
用 ALTER USER 切换回 mysql_native_password 插件
必须在 MySQL 命令行(或已有 root 权限的其他客户端)中执行,phpMyAdmin 自身无法修改自己的登录用户插件:
ALTER USER 'your_username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';
-
'your_username'和'localhost'要和实际用户 host 完全一致(可用SELECT User, Host FROM mysql.user;查) - 改完必须执行
FLUSH PRIVILEGES;才生效 - 如果用户 host 是
'%'或具体 IP,不能写成'localhost',否则报错There is no such grant defined for user - 该操作仅影响指定用户,不影响其他用户或 MySQL 全局默认插件
phpMyAdmin 连接失败时先确认当前用户插件类型
连不上时别急着改密码,先查清楚到底用了什么插件:
SELECT User, Host, plugin FROM mysql.user WHERE User = 'your_username';
- 返回结果中
plugin字段是caching_sha2_password→ 必须切回mysql_native_password - 如果是
mysql_native_password但还是连不上,问题在密码本身或 phpMyAdmin 配置(如config.inc.php中$cfg['Servers'][$i]['password']没更新) - 注意:MySQL 5.7 及更早版本没有
caching_sha2_password,此问题只出现在 8.0+
不想降级插件?那就升级 phpMyAdmin 版本
phpMyAdmin 5.2.0+ 开始原生支持 caching_sha2_password,但需满足两个条件:
立即学习“PHP免费学习笔记(深入)”;
- PHP 必须启用
openssl扩展(extension=openssl在php.ini中已开启) - MySQLi 扩展版本 ≥ 1.1.0(可通过
phpinfo()查mysqli.client_version) - 旧版 phpMyAdmin(如 4.x)即使加了 openssl 也无济于事,必须升级到 5.2+ 并确认
$cfg['Servers'][$i]['auth_type'] = 'cookie'或'config'正常
插件切换和客户端支持是两回事——改插件是最快解法,但长期看,保持插件为 caching_sha2_password 更安全,前提是整个链路(PHP、扩展、phpMyAdmin)都跟得上。



















