[root@132 ~]# service mysqld stop 停止 MySQL: [确定] [root@132 ~]# mysqld_safe --skip-grant-tables & [1] 2219 [root@132 ~]# Starting mysqld daemon with databases from /var/lib/mysql
[root@132 ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> update user set password=password("123456") where user="root"; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
mysql> exit Bye [root@132 ~]# service mysqld restart STOPPING server from pid file /var/run/mysqld/mysqld.pid 110328 10:30:16 mysqld ended
停止 MySQL: [确定] 启动 MySQL: [确定] [1]+ Done mysqld_safe --skip-grant-tables [root@132 ~]# mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
网络 上有很多办法,但是我发现都不成功,后来经过某位大师的提醒,说是MySQL的user数据库有空白行,删掉之后就OK。果然。
mysql> select User,Password from user; +------+------------------+ | User | Password | +------+------------------+ | root | 565491d704013245 | | root | 565491d704013245 | | root | 565491d704013245 | | | | | | | +------+------------------+ 5 rows in set (0.00 sec)
mysql> delete from user where user=""; Query OK, 2 rows affected (0.01 sec)
mysql> select User,Password from user; +------+------------------+ | User | Password | +------+------------------+ | root | 565491d704013245 | | root | 565491d704013245 | | root | 565491d704013245 | +------+------------------+ 3 rows in set (0.00 sec)
mysql> update user set password=password("123456") where user="root"; Query OK, 0 rows affected (0.00 sec) Rows matched: 3 Changed: 0 Warnings: 0
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
mysql> quit Bye [root@132 ~]# service mysqld restart STOPPING server from pid file /var/run/mysqld/mysqld.pid 110328 11:53:24 mysqld ended
停止 MySQL: [确定] 启动 MySQL: [确定] [1]+ Done mysqld_safe --skip-grant-tables [root@132 ~]# [root@132 ~]# [root@132 ~]# mysql -h localhost -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> quit Bye [root@132 ~]# mysql -h localhost -uroot ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@132 ~]# |