1.先將資料庫服務停用:
#/etc/init.d/mysql stop
2.在「背景」模式執行 mysqld_safe, 並跳過權限檢查
#mysqld_safe --skip-grant-tables &
3.以 root帳號登入,此時已經不會詢問密碼
mysql --user=root mysql
4.更換 root密碼,new-pass即是新密碼
mysql> update user set Password=PASSWORD('new-pass') WHERE User='root';
5.寫入權限 flush privileges
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
忘了mysql的root密碼