Centos6.7下mysql5.5.32忘记数据库的root密码怎么破?

Centos6.7下mysql5.5.32忘记数据库的root密码怎么破?


有一天你兴高采烈的准备去连接mysql服务器时间,发现如下一幕,你该怎么办呢?

[root@abao ~]# mysql -uroot -p

Enter password: 

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)


不怕,不怕,ABAO阿宝来帮你解决这个问题哈,步骤如下:


1、查看当前安装的mysql版本:

[root@abao ~]# mysql -V

mysql  Ver 14.14 Distrib 5.5.32, for Linux (x86_64) using readline 5.1

2、停止mysql服务:

[root@abao ~]# service mysqld stop

Shutting down MySQL. SUCCESS! 

3、进入到skip-grant-tables模式:

[root@abao ~]# mysqld_safe --skip-grant-tables

170411 00:35:07 mysqld_safe Logging to '/data/abao67.err'.

170411 00:35:07 mysqld_safe Starting mysqld daemon with databases from /data

    此时新打开一个窗口

现在就不需要密码就可以进入mysql了:

[root@abao ~]# mysql

进入mysql系统数据库:

mysql> use mysql

修改root账户密码:

mysql> update user set password=password("12345") where user="root";

刷新权限:

mysql> flush privileges;

mysql> exit


停止mysql进程:

[1]+ Stopped mysqld_safe --skip-grant-tables


启动mysql:

[root@abao ~]# service mysqld start

4、使用刚才修改的密码进入mysql:

[root@abao ~]# mysql -uroot -p12345

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.32-log Source distribution


Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;

+---------------------+

| Database            |

+---------------------+

| information_schema  |

| #mysql50#lost+found |

| mysql               |

| performance_schema  |

| test                |

+---------------------+

5 rows in set (0.01 sec)


恭喜你,修改完成啦!

本文 暂无 评论

回复给

Top