DEBUG.WIKI
RackNerd;$21.99/年 · 1GB KVM
搬瓦工;先看线路,再选 VPS;CN2 GIA · 对应线路套餐;查看线路 →
腾讯云;让你的想法跑起来;轻量服务器 · 建站 / Docker / API;查看产品 →

解决 MariaDB MaxScale 报错 Client authentication failed 插件密码握手失败修复

排查 客户端连接 MaxScale 报 Access denied for user 或 Client authentication failed,分析 caching_sha2_password 与 mysql_native_password 插件兼容性。

问题现象

MySQL 8.0 升级后,应用通过 MaxScale 连接认证失败:

ERROR 1045 (28000): Access denied for user 'app'@'10.0.1.15' (using password: YES)
MaxScale 日志: [authenticator] Client authentication failed for user 'app'. Backend plugin mismatch.

触发根因

  1. MySQL 8.0 默认认证插件为 caching_sha2_password,而旧版本 MaxScale 节点仅完全支持 mysql_native_password 算法;
  2. MaxScale 本身配置的监控用户缺少访问 mysql.user 表的读取特权,无法预先拉取用户的密码 Hash 进行中间件预验证。

解决步骤

确保后端数据库监控用户具备充分元数据权限

在 MySQL 主库上授予权限:

GRANT SELECT ON mysql.user TO 'maxuser'@'%';
GRANT SELECT ON mysql.db TO 'maxuser'@'%';
GRANT SHOW DATABASES ON *.* TO 'maxuser'@'%';
FLUSH PRIVILEGES;

在 MaxScale 服务配置中明确指定密码协议

编辑 /etc/maxscale.cnf:

[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MariaDBClient
port=3306
authenticator_options=auth_plugin=caching_sha2_password

验证确认

重启 MaxScale 验证连接:

mysql -u app -p -h 127.0.0.1 -P 3306

客户端秒级握手成功,进入 SQL 控制台。