標籤:
重設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)