重置MySQL8.0 Root密码

  1. 停止MySQL服务
  2. 跳过权限检查启动MySQL服务:
1
sudo mysqld_safe --skip-grant-tables &
  1. 使用root账号登录MySQL:
1
mysql -u root
  1. 更新Root密码:
1
2
flush privileges;
alter user 'root'@'localhost' identified by 'root';

如不先执行“flush privileges;”,则可能会提示以下错误信息:

1
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  1. 刷新权限:
1
flush privileges;
  1. 重启MySQL服务。