故障现象
ERROR 1045 (28000): Access denied for user 'xxx'@'host'- 密码正确但仍报错(主机白名单问题)
- MySQL 8.0 升级后认证插件不兼容
解决步骤
- 确认账号和主机白名单
SELECT user, host, plugin FROM mysql.user WHERE user='app_user';
- 重置密码
ALTER USER 'app_user'@'%' IDENTIFIED BY 'NewSecurePassword!'; FLUSH PRIVILEGES;
- MySQL 8.0 兼容旧客户端(caching_sha2_password → mysql_native_password)
ALTER USER 'app_user'@'%' IDENTIFIED WITH mysql_native_password BY 'NewPass!'; FLUSH PRIVILEGES;
- 忘记 root 密码时:使用
--skip-grant-tables模式恢复systemctl stop mysqld # 在 my.cnf [mysqld] 段添加:skip-grant-tables systemctl start mysqld mysql -uroot # 无需密码登录后修改密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewRootPass!'; # 删除 skip-grant-tables,重启