1)打開命令提示符拼苍,關(guān)閉MySQL服務(wù):net stop mysql
2)輸入 :mysqld --console --skip-grant-tables --shared-memory
3)保持當(dāng)前窗口摔桦,另開新的cmd窗口液肌,輸入mysql,跳過密碼登錄焰络,進入mysql
4)修改密碼 戴甩,轉(zhuǎn)載自https://blog.csdn.net/wolf131721/article/details/93004013
MySql 從8.0開始修改密碼有了變化,在user表加了字段authentication_string闪彼,修改密碼前先檢查authentication_string是否為空
①如果不為空
use mysql;
update user set authentication_string='' where user='root';--將字段置為空
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密碼為root
②如果為空
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密碼為root
注意:
如果出現(xiàn)如下錯誤
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION
需要執(zhí)行
flush privileges;
然后再執(zhí)行
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密碼為root