MySQL重設root密碼的幾種方法(windows+Linux)

來源:互聯網
上載者:User

標籤:

重設root密碼的方法:

windows系統下:
1、停止mysql服務;
2、建立檔案init-root.txt,寫上如下內容:
update mysql.user set password = password(‘newpwd‘) where user = ‘root‘;
flush privileges;
儲存;
3、開啟命令列,輸入:C:\mysql\bin\mysqld --init-file=C:\\mysql-init.txt
--init-file 選項指向初始化的檔案

如果MySQL是通過GUI介面安裝嚮導安裝的話,如下:
C:\> "C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe"
--defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.6\\my.ini"
--init-file=C:\\mysql-init.txt
--defaults-file 選項指向mysql的設定檔

4、服務重啟後密碼已經重設,可以刪掉init-root.txt檔案。


linux下,第一種方法類似windows中:
1、停止mysql服務(kill掉進程);
2、建立檔案init-root,寫上如下內容:
update mysql.user set password = password(‘newpwd‘) where user = ‘root‘;
flush privileges;
儲存;
3、在shell中運行: mysqld_safe --init-file=/home/me/mysql-init &

4、服務重啟,可以刪掉init-root.txt檔案。

 

所有平台都可用的方法:
1、停止mysqld服務,
2、配置my.conf檔案,加入: --skip-grant-tables選項,跳過許可權檢查; --skip-networking 選項阻止遠程客戶網路連接;
3、重啟mysqld服務,
shell> service mysqld start
4、登入client,
shell> mysql
5、更改密碼:
mysql> update mysql.user set password = password(‘newpwd‘) where user=‘root‘;
mysql> flush privileges;
6、關閉mysqld服務,刪除--skip-grant-tables和--skip-networking選項,重啟服務即可

 

參考:

MySQL官方文檔:
http://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html 

 

MySQL重設root密碼的幾種方法(windows+Linux)

聯繫我們

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