Windows系統(tǒng)下MySQL忘記root密碼的2種解決辦法
方法1:
對于忘記MySQL root用戶密碼,常規(guī)的解決方法是啟動的時(shí)候加 skip-grant-tables 選項(xiàng),在繞過密碼認(rèn)證之后,進(jìn)入MySQL數(shù)據(jù)庫系統(tǒng),以便進(jìn)行修復(fù)或重置密碼等操作。
在window下,怎么操作呢,接下來為您介紹。
1、window下關(guān)閉MySQL相關(guān)服務(wù)
打開cmd窗口,我這里MySQL服務(wù)名稱設(shè)置為了MySQL8031,所以這里是 net stop mysql8031
2、重新啟動MySQL
用下面的命令啟動MySQL服務(wù)
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 啟動可以跳過密碼驗(yàn)證
3、打開另外一個(gè)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、設(shè)置新的root密碼
update mysql.user set authentication_string='' where user='root'; flush privileges; ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
5、關(guān)閉上述終端,重新啟動mysql
net start mysql8031
這樣就可以用修改后的密碼登錄進(jìn)去了
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:
接下來,介紹另外一種更簡單的方式。
新建一個(gè)newpass.txt文件(可以將它放在my.ini同目錄)文件內(nèi)容為:
ALTER user root@'localhost' identified by 'root';
關(guān)閉MySQL服務(wù):
net stop mysql8031
用下面的命令啟動MySQL服務(wù):
D:\MySQL8031\bin\mysqld.exe --defaults-file=“D:\MySQL8031\my.ini” --init-file=“D:\MySQL8031\newpass.txt”
具體的my.ini文件和newpass.txt文件要改成實(shí)際的位置
命令執(zhí)行后界面沒有變化執(zhí)行下一步。
按Ctrl+C終止運(yùn)行,并重新啟動Windows服務(wù)
總結(jié)
到此這篇關(guān)于Windows系統(tǒng)下MySQL忘記root密碼的2種解決辦法的文章就介紹到這了,更多相關(guān)Windows MySQL忘記root密碼解決內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
mysql如何將表結(jié)構(gòu)導(dǎo)出到excel
這篇文章主要介紹了mysql如何將表結(jié)構(gòu)導(dǎo)出到excel,幫助大家更好的理解和使用MySQL數(shù)據(jù)庫,感興趣的朋友可以了解下2020-09-09CentOS7.3下mysql 8.0.13安裝配置方法圖文教程
這篇文章主要為大家詳細(xì)介紹了CentOS7.3下mysql 8.0.13安裝配置方法圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11MySQL數(shù)據(jù)庫子查詢語法規(guī)則詳解
子查詢是在查詢語句里面再嵌套一個(gè)查詢,這是因?yàn)槲覀冊谔崛?shù)據(jù)的時(shí)候有很多不知道的數(shù)據(jù)產(chǎn)生了依賴關(guān)系。本文為大家總結(jié)了一下MySQL數(shù)據(jù)庫子查詢語法規(guī)則,感興趣的可以了解一下2022-08-08mysql數(shù)據(jù)庫單表最大存儲依據(jù)詳解
這篇文章主要為大家介紹了mysql數(shù)據(jù)庫單表最大存儲的依據(jù)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07