3

mysql 忘记root密码 如何找回

 2 years ago
source link: http://www.koogg.com/2020/11/27/mysql-%e5%bf%98%e8%ae%b0root%e5%af%86%e7%a0%81-%e5%a6%82%e4%bd%95%e6%89%be%e5%9b%9e/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

mysql 忘记root密码 如何找回

2020年11月27日 788点热度 4人点赞 0条评论

通常在使用Mysql数据库时,如果长时间没有登陆,或者由于工作交接完成度不高,会导致数据库root登陆密码忘记,

一、更改my.cnf配置文件

1.用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf,当然我用mobaxterm直接右键打开即可。

2.在[mysqld]下添加skip-grant-tables,然后保存并退出

Snipaste_2020-11-27_10-39-28.png

3.重启mysql服务:service mysqld restart

二、更改root用户名

1.重启以后,执行mysql命令进入mysql命令行

2.修改root用户密码

update mysql.user set authentication_string = password('新密码') where user = 'root';
flush privileges;
exit;

Snipaste_2020-11-27_11-02-43.png

3.把/etc/my.cnf中的skip-grant-tables注释掉,然后重启mysql,即:service mysqld restart

好了,下面就可以用root新的密码登录了!

Snipaste_2020-11-27_11-04-17.png


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK