环境: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 //服务状态查看
Copy
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字段
Copy
重置成新密码
alter user 'root'@'localhost' identified by 'newpassword';
备注:Mysql8.0修改密码方式已有变化(此处是个坑,需要注意)
Mysql8.0之前:
update user set password=password('root') where user='root';
Copy
6、vim /etc/my.cnf,删除 skip-grant-table#
7、再次重启 mysql 服务#
8、使用新密码登录 mysql#
mysql -uroot -proot
Copy
<div class="meta" style="margin: 35px 0px;">
<i class="icon tags"></i>
<a class="ui label small yellow topic-tag" href="https://learnku.com/blog/zhangdeTalk/tags/mysql_487">mysql</a>
<a class="ui label small yellow topic-tag" href="https://learnku.com/blog/zhangdeTalk/tags/mysql80_52411">Mysql8.0</a>
<a class="ui label small yellow topic-tag" href="https://learnku.com/blog/zhangdeTalk/tags/reset-password_EB_49466">重置密码</a>
</div>
<blockquote style="font-size: 0.9em;">
本作品采用<a href="https://learnku.com/docs/guide/cc4.0/6589">《CC 协议》</a>,转载必须注明作者和本文链接
</blockquote>
<div>
<a class="ui popover " data-content="作者署名,你可以在『个人资料』里设置" style="display: block;width: 30px;color: #ccc;margin: 22px 0 8px;"><i class="icon paw" aria-hidden="true"></i></a>
<span class="rm-link-color">
阿德
</span>
</div>
</div>