MySQL Root密碼丟失解決方案總結

來源:互聯網
上載者:User

標籤: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密碼丟失解決方案總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.