1. 通過services.msc 停止mysqld 服務
2.開啓跳過密碼驗證登錄的MySQL服務 輸入命令 shell 中
切換到mysq\bin目錄
.\mysqld --console --skip-grant-tables --shared-memory
3.再打開一個新的shell,無密碼登錄MySQL,輸入登錄命令:
.\mysql -u root -p #進入了mysql 見提示符 mysql>
4. 密碼置爲空,命令如下:
use mysql
update user set authentication_string='' where user='root';
5.退出mysql,執行命令:
quit # 退出 mysql
exit # 退出 shell
6. 關閉以-console --skip-grant-tables --shared-memory 啓動的MySQL服務
# ctrl C 關閉了第1個 shell ??
7. 在services.msc中 啓動MySQL服務。
8.步驟4密碼已經置空,輸入登錄命令:
mysql -u root -p
Enter password 直接按回車
9. 修改密碼,輸入命令
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼';
10.驗證更改後密碼正確登錄
輸入quit,退出當前登錄,輸入登錄命令:.\mysql -u root -p
輸入密碼,成功登錄.
重置密碼結束。