Mysql的root密码找回

今天打开虚拟机的时候进mysql数据库,发现进不去了,root密码也忘了,搜了一下,记录找回密码过程如下:

1.修改my.conf文件,新增skip-grant-tables
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-grant-tables
2.重启mysql
#/etc/init.d/mysqld restart
Shutting down MySQL. SUCCESS! 
Starting MySQL... SUCCESS!
3.登陆修改root密码
[root@localhost log]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.23-log Source distribution

Copyright (c) 2000, 2011, 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
Database changed
mysql> update user set password = password('root') where user = 'root';
Query OK, 4 rows affected (0.91 sec)
Rows matched: 4  Changed: 4  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)

mysql> quit
Bye
4.删除之前my.conf文件中新增的skip-grant-tables

5.重启DB,登陆正常

6.参数skip-grant-tables说明
这个参数看名字就是skip权限用的,通常用来找回root密码用,相对危险,慎用,特别是在生产上

你可能感兴趣的:(mysql,找回密码)