1.先在安裝目錄找到my.ini配置文件,打開配置文件,找到[mysqld]一行,在下面添加skip-grant-tables后保存該文件,重新啟mysql動服務。
2.執行 mysql -u root -p 密碼為空,直接回車;
usemysql
mysql>update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost';
mysql>Flush privileges;
其中newpassword為root的新密碼。
(可能先前的版本密碼的抬頭是password,5.7.11是 authentication_string,可以select * from user,查看一下)
(老版本)update user set password=password("123456") where user="root";
(5.7.11)update user set authentication_string=password("123456") where user="root";
3.將剛才my.ini配置文件添加的那一行去掉,重啟mysql。