MySQL資料庫的root口令恢複方法總結

來源:互聯網
上載者:User
MySQL資料庫的root口令恢複方法總結

方法一

1. 下載MySQL源碼分發包,不用區分作業系統,我們需要的東西是一樣的;


2. 重新命名自己的mysql的data目錄下的mysql檔案夾為oldmysql;

3. 將源碼包中data目錄下的mysql目錄複寫到你的mysql的data目錄下;

4. 重新啟動mysql,現在mysql的授權關係同全新安裝的一樣,空密碼登陸,然後自行調整授權;

5. 開啟oldmysql這個庫檢查到底出現了什麼問題 ;

6. 如果有備份對系統中原有的資料庫進行完整性檢測,以免被人修改。

方法二

1. 向mysqld server發送kill命令關掉mysqld server(不是 kill -9),存放進程ID的檔案通常在MYSQL的資料庫所在的目錄中。

kill `cat /mysql-data-directory/hostname.pid`

你必須是Linux的root使用者或者是你所啟動並執行SERVER上的同等使用者,才能執行這個操作;

killall -TERM mysqld

2. 使用`--skip-grant-tables’ 參數來啟動 mysqld;

shell>mysqld_safe --skip-grant-tables &

/ bin/safe_mysqld --skip-grant-tables &


3. 使用`mysql -h hostname mysql’命令登入到mysqld server ,用grant命令改變口令。你也可以這樣做:

`mysqladmin -h hostname -u user password ’new password’’

其實也可以用

use mysql; update user set password =password(’yourpass’) where user=’root’

來做到;

shell>mysqladmin -u root flush-privileges password "newpassword"

>use mysql

>update user set password=password("new_pass") where user="root";

>flush privileges;

4. 載入許可權表:

`

mysqladmin -h hostname flush-privileges’

或者使用SQL命令

`FLUSH PRIVILEGES’

當然,在這裡,你也可以重啟mysqld。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.