MySQL8.0 忘记 root 密码下如何修改密码
环境:Linux centos8 4.18.0-80.el8.x86_64、Mysql8.0.18
1、vim /etc/my.cnf,添加skip-grant-table(跳过权限验证)
2、重启mysql服务
systemctl stop mysqld //停止服务
systemctl restart mysqld //重启服务
systemctl status mysqld //服务状态查看
3、刷新权限表:flush privileges;
4、mysql登录:mysql -uroot -p(无需密码)
5、密码重置(Mysql8.0+有变化)
先把root的旧密码置空
use mysql;
update user set authentication_string='' where user='root';
备注:Mysql5.7+ password字段 已改成 authentication_string字段
重置成新密码
alter user 'root'@'localhost' identified by 'newpassword';
备注:Mysql8.0修改密码方式已有变化(此处是个坑,需要注意)
Mysql8.0之前:
update user set password=password('root') where user='root';
6、vim /etc/my.cnf,删除skip-grant-table
7、再次重启mysql服务
8、使用新密码登录mysql
mysql -uroot -proot
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: