參考:https://blog.csdn.net/qq_34102150/article/details/126120056
1、停止MySQL服務,輸入 net stop mysql 停止服務。
2、切換到MySQL的bin文件下,
mysql5.x: mysqld --console --skip-grant-tables --shared-memory
mysqld --console --skip-grant-tables --shared-memory
3、輸入mysql -uroot -p回車,不用輸入密碼,直接按回車跳過,
輸入: use mysql
輸入: update user set password=PASSWORD('123456') where USER='root';
或者: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
輸入: FLUSH PRIVILEGES;
4、重啟服務