本文是在 centos 8 和 MySQL 8 中进行,若其他环境无效欢迎留言评论探讨。
本文主要采用–skip-grant-tables 进行重置密码
1.停止MySQL服务
systemctl stop mysqld
2.设置以root用户运行MySQL,跳过密码验证
mysqld --skip-grant-tables --user=mysql &
3.登录MySQL
mysql
4.刷新权限
flush privileges;
5.修改root用户密码为new-password
alter user 'root'@'localhost' identified by 'new_password';
6.新密码登录
mysql -u root -p