CentOS7下mysql忘记root密码之重置密码

一、序言

今天想连接一下远程centos7数据库,居然,发现密码错误,这就尴尬了,原本打算重装,不过想想也不至于这么坑吧,发现是可以完美重置密码的,不错不错!!

二、正式开搞

1、 nano /etc/my.cnf,在[mysqld]中添加

skip-grant-tables

例如:

[mysqld]
skip-grant-tables

2、重启mysql

systemctl restart mysqld

3、使用用户无密码登录

mysql -uroot -p (直接点击回车,密码为空)

4、选择数据库

use mysql;

5、修改root密码

update user set authentication_string=password('123456') where user='root';

6、.刷新权限

flush privileges;

7、.退出

exit;

8 、将第一步添加的skip-grant-tables删除

9、重启mysql

service mysql restart

发布了40 篇原创文章 · 获赞 11 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Chen_RuiMin/article/details/105436904