1、進(jìn)入到mysql安裝目錄的bin文件夾下,打開cmd,關(guān)閉mysql數(shù)據(jù)庫(也可以計(jì)算機(jī)右鍵,管理,服務(wù)和應(yīng)用程序,服務(wù),找到mysql的服務(wù)進(jìn)行關(guān)閉)

輸入命令行:net stop mysql服務(wù)名
回車即可
2、輸入mysqld --skip-grant-tables 回車
(--skip-grant-tables的意思是啟動MYSQL服務(wù)的時(shí)候跳過權(quán)限表驗(yàn)證)
注意:這時(shí)候,剛剛打開的cmd命令窗口已經(jīng)不能使用了,重新再打開一個(gè)cmd命令窗口進(jìn)行接下來的操作
3、在新打開的cmd窗口中輸入mysql回車,如下圖:

4、連接權(quán)限數(shù)據(jù)庫:use mysql
5、修改數(shù)據(jù)庫連接密碼:update user set password=password('123456') where user=root;
注意:這里的'123456'為新密碼,可以自己設(shè)置新的密碼。注意后面的';'不能遺漏

百度了一下,說是mysql數(shù)據(jù)庫下已經(jīng)沒有了password這個(gè)字段了,而是authentication_string,
所以,命令改為了 :
update MySQL.user set authentication_string=password('123456') where user='root';即可
如下圖:

6、刷新權(quán)限:flush privileges;
7、退出mysql:quit
8、修改root密碼后需要執(zhí)行下面的語句和新修改的密碼,不然開啟mysql時(shí)會出錯(cuò)
mysqladmin -u root -p shutdown
Enter password:新密碼
9、重啟mysql
命令:net start mysql
或者通過服務(wù)開啟
借鑒:https://blog.csdn.net/weidong_y/article/details/80493743
htttps://blog.csdn.net/csdnones/article/details/53706762