1.停止mysql服務:
net stop mysql
2.開啟跳過密碼驗證登錄的MySQL服務
mysqld --console --skip-grant-tables --shared-memory
3.再打開一個新的cmd,無密碼登錄MySQL
mysql -u root -p
4. 密碼置為空
use mysql
update user set authentication_string='' where user='root';
5.退出mysql
quit
6. 關閉以-console --skip-grant-tables --shared-memory 啟動的MySQL服務,
7. 啟動MySQL服務。
net start mysql
8.步驟4密碼已經置空,所以無密碼狀態登錄MySQL,輸入登錄命令:mysql -u root -p
9.修改密碼:
ALTER USER
'root'
@
'localhost'
IDENTIFIED BY
'123456'
;
10.刷新重新進入
quit;
net stop mysql
net start mysql
mysql -u root -p
輸入密碼,登錄成功。