From:
#有的时候我们因为一些原因需要重新设置root密码,我做了一下尝试,记录下步骤,供有序要得朋友们参考。
[root@CactiEZ ~]# mysql -u root -p #尝试登录mysql
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) #因密码不正确登录失败
[root@CactiEZ ~]# service mysqld stop #停止mysqld
Stopping mysqld: [ OK ]
You have new mail in /var/spool/mail/root
[root@CactiEZ ~]# mysqld_safe --skip-grant-tables& #跳过权限表启动
[1] 20462
[root@CactiEZ ~]# 130326 14:01:10 mysqld_safe Logging to '/var/log/mysqld.log'.
130326 14:01:10 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@CactiEZ ~]# mysql -u root #以root身份登录mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.47 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> UPDATE
-> mysql.user
-> SET
-> Password = password('yourpasswd')
-> WHERE
-> User = 'root'; #更改root用户的密码
Query OK, 3 rows affected (0.02 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@CactiEZ ~]# service mysqld restart #将mysqld重新启动
130326 14:03:51 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[1]+ Done mysqld_safe --skip-grant-tables
[root@CactiEZ ~]# service mysqld start
Starting mysqld: [ OK ]
[root@CactiEZ ~]# mysql -u root -p #使用新设置的密码登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.47 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> #登录成功
阅读(1051) | 评论(0) | 转发(1) |