Saturday, May 06, 2006

復原 MySQL root 密碼

忘記了 MySQL 的 root 密碼,可以用以下方法重新設定:

1. 關閉 MySQL 伺服器。

2. 用以下指令啟動 MySQL,以跳過檢查權限的資料表
mysqld_safe –skip-grant-tables &<

3. 現在己經可以用空密碼進入 MySQL
mysql -u root

4. 進入 MySQL 後執行以下指令更改 mysql root 密碼:
mysql> update mysql.user set password=PASSWORD(”new_password”) where User=’root’;
mysql> flush privileges;
mysql> quit

5. 最後只需重新啟動 MySQL,便可以用新設定的密碼進入了。