mysql忘记密码处理

来源:互联网 发布:数据透视表值显示文本 编辑:程序博客网 时间:2024/05/19 01:09
1、首先停止数据库

[root@wolf bin]# service mysqld stop

2、在my.cnf中加入skip-grant-tables 

[root@wolf bin]# vi /etc/my.cnf 
在[mysqld]的段中加上一句:skip-grant-tables 
[mysqld]
skip-grant-tables 
[root@wolf bin]# service mysqld stop
Shutting down MySQL..                                      [  OK  ]
[root@wolf bin]# service mysqld start

Starting MySQL.                                            [  OK  ]

3、进入mysql

[root@wolf bin]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

4、update更新密码

mysql> UPDATE user SET Password = password ( '123' ) WHERE User='root'; 
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges ; 
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

5、在[mysqld]的段中删除或注释:skip-grant-tables 
[mysqld]
#skip-grant-tables 

[root@wolf bin]# service mysqld restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL.                                            [  OK  ]
[root@wolf bin]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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.
0 0
原创粉丝点击