標籤:blog http ar os 使用 sp 檔案 on art
1. 檢查my.cnf,看看有沒有密碼......靠這也算一條啊
2. 如果能夠重啟,
首先使用–skip-grant-tables參數重啟,然後改密碼,再去掉–skip-grant-tables參數重啟, 注意–skip-grant-tables的安全問題http://code.openark.org/blog/mysql/dangers-of-skip-grant-tables, 根據火丁筆記http://huoding.com/2011/06/12/85,還需要加上--skip-networking
$ mysqld_safe --skip-grant-tables --skip-networking &
接著使用SQL重設密碼後,記得去掉skip-networking,以正常方式重啟MySQL服務:
$ /etc/init.d/mysqld restart
上面的方法需要重啟兩次服務,實際上還能更優雅一點,重啟一次即可: 首先需要把用到的SQL語句儲存到一個文字檔裡(/path/to/init/file):
UPDATE mysql.user SET Password=PASSWORD(‘...‘) WHERE User=‘...‘ AND Host= ‘...‘;
FLUSH PRIVILEGES;
接著使用init-file參數啟動MySQL服務,
$ /etc/init.d/mysql stop
$ mysqld_safe --init-file=/path/to/init/file &
此時,密碼就已經重設了,最後別忘了刪除檔案內容,免得泄露密碼。
3.on linux / unix ONLY
$ cd data/mysql
$ cp -rp user.MYD bck_user.MYD_`date +%Y%m%d`cp -rp user.MYD /tmp/user.MYD
$ vi /tmp/user.MYD #(edit the hashed passwords next to root*)cp -rp /tmp/user.MYD user.MYD
$ sudo kill -HUP `pidof mysqld`
4.using an init-file
4.這裡還有個第四點 using an init-file, which leads to just one restart of the database instead of two. It also avoids the security issue involved with using skip-grant-tables.
5.如果你在MySQL裡邊,那麼可選擇的辦法就太多了
參考 <http://www.cnblogs.com/rootq/archive/2009/05/13/1456335.html>
MySQL Root密碼丟失解決方案總結