You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS系统下无法访问MySQL 8.0.33的技术求助

解决MySQL 8.0 "ERROR 1045 (28000): Access denied for user 'root'@'localhost'" 问题

针对你遇到的MySQL 8服务正常但root登录失败的问题,可按以下步骤排查解决:

步骤1:尝试使用安装时生成的临时密码

MySQL 8首次安装后会自动生成临时root密码并写入日志,先尝试用该密码登录:

grep 'temporary password' /var/log/mysqld.log

找到日志中类似A temporary password is generated for root@localhost: xxxxxxx的记录,复制密码后执行:

mysql -u root -p

输入临时密码登录成功后,立即修改为符合复杂度要求的新密码(需包含大小写字母、数字、特殊字符):

ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';

步骤2:跳过授权表重置root密码

若临时密码无效或已丢失,通过跳过授权表的方式重置:

  1. 停止MySQL服务:
    systemctl stop mysqld
    
  2. 编辑MySQL配置文件(通常路径为/etc/my.cnf或/etc/mysql/my.cnf),在[mysqld]区块添加以下两行:
    skip-grant-tables
    skip-networking
    
  3. 重启MySQL服务:
    systemctl start mysqld
    
  4. 无密码登录MySQL:
    mysql -u root
    
  5. 切换至mysql系统库,重置root用户的认证信息并设置新密码:
    USE mysql;
    UPDATE user SET authentication_string = '', plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
    FLUSH PRIVILEGES;
    ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';
    
  6. 退出MySQL,停止服务,删除配置文件中添加的两行配置,再重启服务:
    exit
    systemctl stop mysqld
    # 编辑my.cnf移除skip-grant-tables和skip-networking
    systemctl start mysqld
    
  7. 使用新密码登录验证:
    mysql -u root -p
    

额外检查

  • 确保输入密码时没有大小写或特殊字符的输入错误(可在输入前切换至英文输入法)
  • 检查mysql.user表中root@localhost的plugin字段是否为mysql_native_password或caching_sha2_password,避免异常插件导致登录失败

内容的提问来源于stack exchange,提问作者piyush

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 05:43:12