MySQL如果忘記了root密碼,可以很方便的找回,方法如下:
1. 先殺掉MySQL的所有進程;
#killall -TERM mysqld
2. 使用skip-grant-tables這個選項啟動MySQL;
#/user/bin/safe_mysqld --skip-grant-tables &
3. 這時你就可以不使用密碼登陸MySQL了;
#mysql -h localhost -u root -p
mysql> use mysql
mysql> update user set password=password('newpassword') where user='root';
mysql> flush privileges;
mysql> exit;
4. 關閉MySQL;
#/user/bin/mysqladmin -u root -p shutdown
Enter password: www.2cto.com
STOPPING server from pid file /usr/local/mysql/data/ws01.pid
071218 11:30:19 mysqld ended
[1]+ Done /usr/local/mysql/bin/safe_mysqld --skip-grant-tables (wd: /ceno/product/cacti/include)
(wd now: /usr/local/mysql/bin)
5. 正常啟動MySQL;
#/user/bin/mysqld_safe --user=mysql &
[1] 5583
Starting mysqld daemon with databases from /usr/local/mysql/data
6. 現在趕快試試你的新密碼吧;
作者 wenrunchang123