忘记mysql密码

忘记密码
1>停止服务

[root@centos6 ~]# service mysqld stop
停止 mysqld:                                              [确定]

 2>修改配置文件

[root@centos6 ~]# vim /etc/my.cnf
[mysqld]
......
skip-grant-tables    //在[mysqld]中加入该字段
# Disabling symbolic-links is recommended to prevent assorted security risks

 3>重启服务,并登录

[root@centos6 ~]# service mysqld start
正在启动 mysqld:                                          [确定]
[root@centos6 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 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>

 4>切换当前数据库

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

 5>修改密码

mysql> update user set password=password(‘123456‘) where user=‘root‘ and Host = ‘localhost‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> exit
Bye

 6>停止服务,修改配置文件注释掉skip-grant-tables该字段,并重新启动服务,登录

[root@centos6 ~]# service mysqld stop
停止 mysqld:                                              [确定]
[root@centos6 ~]# vim /etc/my.cnf
[mysqld]
......
# skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks

[root@centos6 ~]# service mysqld start
正在启动 mysqld:                                          [确定]
[root@centos6 ~]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 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>     //成功

 

忘记mysql密码

上一篇:数据库学习之二:mysql安装及启动


下一篇:andorid(3) 使用sqllite进行数据持久化