1、管理員身份打開命令行
net stop mysql
2、跳過用戶驗證
mysqld --skip-grant-tables
3、管理員身份打開新窗口,輸入
mysql
4、進入mysql數據庫
use mysql;
5、重新設置密碼
update user set password=password('123456') where user='root' and host='localhost';
如果出現以下錯誤,則將命令改爲
update user set authentication_string=password('123456') where user='root' and host='localhost';
修改後exit退出
6、啓動mysql服務並登錄
net start mysql
mysql -uroot -p123456