一、背景
兩臺電腦同時裝數據庫,導致忘記之前電腦的數據庫密碼,百度了各種找回密碼的方式,最終發現5.0版本的MySQL與8.0以後的找回方式不同!!!
二、解決方案
1.先打開第一個cmd命令窗口
step1.停用mysql服務
net stop mysql
step2.跳過輸入密碼的驗證
mysqld --console --skip-grant-tables --shared-memory
2.打開第2個cmd命令窗口(第一個不要關閉)
step1.啓動mysql服務
net start mysql
step2.輸入用戶名、密碼(密碼不用輸直接回車即可)
mysql -u root -p
step3.將密碼置空
use mysql
alter user set authentication_string='' where user='user';
exit
3.關掉兩個cmd窗口,打開新的窗口,無密碼登錄(還是直接回車)
step1.登錄後,修改密碼
alter user 'root'@'localhost' identified with mysql_native_password by '111111';
#with mysql_native_password 是爲了連接Navicat不報錯
step2.一定要記得刷新權限!!!
flush privileges