linux下mysql忘记密码


首先修改mysql配置文件:

在[mysqld]下面添加skip-grant-tables

[root@qqyunvn ~]# vim /etc/my.cnf
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
datadir = /usr/local/mysql/var
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
skip-grant-tables

重新启动mysql

[root@qqyunvn ~]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!

使用命令mysql登陆进去
[root@qqyunvn ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, 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(’这里填写您要更新的密码’) WHERE User = ’root’ ;
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

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

mysql> quit
Bye

修改完成后删除刚才添加的参数

skip-grant-tables
[root@qqyunvn ~]# vim /etc/my.cnf

[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
datadir = /usr/local/mysql/var
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
#skip-grant-tables

重启mysql服务
[root@qqyunvn ~]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!

重新登录,用您刚设置的密码,显示成功!QQ截图20130927120415.jpg

 


Whatever is worth doing is worth doing well.