Windows系統(tǒng)下MySQL忘記root密碼的2種解決辦法
方法1:
對于忘記MySQL root用戶密碼,常規(guī)的解決方法是啟動的時候加 skip-grant-tables 選項,在繞過密碼認證之后,進入MySQL數(shù)據(jù)庫系統(tǒng),以便進行修復或重置密碼等操作。
在window下,怎么操作呢,接下來為您介紹。
1、window下關閉MySQL相關服務
打開cmd窗口,我這里MySQL服務名稱設置為了MySQL8031,所以這里是 net stop mysql8031
2、重新啟動MySQL
用下面的命令啟動MySQL服務
C:\Users\Administrator>cd /d D:\MySQL8031\bin D:\MySQL8031\bin>mysqld --console --skip-grant-tables --shared-memory
通過mysqld --console --skip-grant-tables --shared-memory 啟動可以跳過密碼驗證
3、打開另外一個cmd窗口登錄MySQL
C:\Users\Administrator>cd /d D:\MySQL8031\bin D:\MySQL8031\bin>mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 8.0.31 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
4、設置新的root密碼
update mysql.user set authentication_string='' where user='root'; flush privileges; ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
5、關閉上述終端,重新啟動mysql
net start mysql8031
這樣就可以用修改后的密碼登錄進去了
C:\Users\Administrator>cd /d D:\MySQL8031\bin\ D:\MySQL8031\bin>mysql -uroot -proot mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.31 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
方法2:
接下來,介紹另外一種更簡單的方式。
新建一個newpass.txt文件(可以將它放在my.ini同目錄)文件內容為:
ALTER user root@'localhost' identified by 'root';
關閉MySQL服務:
net stop mysql8031
用下面的命令啟動MySQL服務:
D:\MySQL8031\bin\mysqld.exe --defaults-file=“D:\MySQL8031\my.ini” --init-file=“D:\MySQL8031\newpass.txt”
具體的my.ini文件和newpass.txt文件要改成實際的位置
命令執(zhí)行后界面沒有變化執(zhí)行下一步。
按Ctrl+C終止運行,并重新啟動Windows服務
總結
到此這篇關于Windows系統(tǒng)下MySQL忘記root密碼的2種解決辦法的文章就介紹到這了,更多相關Windows MySQL忘記root密碼解決內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
CentOS7.3下mysql 8.0.13安裝配置方法圖文教程
這篇文章主要為大家詳細介紹了CentOS7.3下mysql 8.0.13安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-11-11MySQL數(shù)據(jù)庫子查詢語法規(guī)則詳解
子查詢是在查詢語句里面再嵌套一個查詢,這是因為我們在提取數(shù)據(jù)的時候有很多不知道的數(shù)據(jù)產(chǎn)生了依賴關系。本文為大家總結了一下MySQL數(shù)據(jù)庫子查詢語法規(guī)則,感興趣的可以了解一下2022-08-08mysql數(shù)據(jù)庫單表最大存儲依據(jù)詳解
這篇文章主要為大家介紹了mysql數(shù)據(jù)庫單表最大存儲的依據(jù)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07