Windows系統(tǒng)下MySQL忘記root密碼的2種解決辦法
方法1:
對(duì)于忘記MySQL root用戶密碼,常規(guī)的解決方法是啟動(dòng)的時(shí)候加 skip-grant-tables 選項(xiàng),在繞過密碼認(rèn)證之后,進(jìn)入MySQL數(shù)據(jù)庫(kù)系統(tǒng),以便進(jìn)行修復(fù)或重置密碼等操作。
在window下,怎么操作呢,接下來為您介紹。
1、window下關(guān)閉MySQL相關(guān)服務(wù)
打開cmd窗口,我這里MySQL服務(wù)名稱設(shè)置為了MySQL8031,所以這里是 net stop mysql8031

2、重新啟動(dòng)MySQL
用下面的命令啟動(dòng)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 啟動(dòng)可以跳過密碼驗(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)閉上述終端,重新啟動(dòng)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:
接下來,介紹另外一種更簡(jiǎn)單的方式。
新建一個(gè)newpass.txt文件(可以將它放在my.ini同目錄)文件內(nèi)容為:
ALTER user root@'localhost' identified by 'root';
關(guān)閉MySQL服務(wù):
net stop mysql8031

用下面的命令啟動(dòng)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)行,并重新啟動(dòng)Windows服務(wù)

總結(jié)
到此這篇關(guān)于Windows系統(tǒng)下MySQL忘記root密碼的2種解決辦法的文章就介紹到這了,更多相關(guān)Windows MySQL忘記root密碼解決內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MySQL數(shù)據(jù)同步出現(xiàn)Slave_IO_Running:?No問題的解決
本人最近工作中遇到了Slave_IO_Running:NO報(bào)錯(cuò)的情況,通過查找相關(guān)資料終于解決了,下面這篇文章主要給大家介紹了關(guān)于MySQL數(shù)據(jù)同步出現(xiàn)Slave_IO_Running:?No問題的解決方法,需要的朋友可以參考下2023-05-05
一文詳解MySQL單表存多大的數(shù)據(jù)量比較合適
MySQL單表的數(shù)據(jù)量上限主要受存儲(chǔ)引擎和文件系統(tǒng)限制,理論值可達(dá)數(shù)千萬至數(shù)十億行,但實(shí)際建議控制在千萬級(jí)以內(nèi)以保證性能,這篇文章主要介紹了MySQL單表存多大的數(shù)據(jù)量比較合適的相關(guān)資料,需要的朋友可以參考下2026-02-02
MySQL并發(fā)更新數(shù)據(jù)時(shí)的處理方法
在后端開發(fā)中我們不可避免的會(huì)遇見MySQL數(shù)據(jù)并發(fā)更新的情況,作為一名后端研發(fā),如何解決這類問題也是必須要知道的,同時(shí)這也是面試中經(jīng)常考察的知識(shí)點(diǎn)。2019-05-05
MySQL中使用JSON存儲(chǔ)數(shù)據(jù)的實(shí)現(xiàn)示例
本文主要介紹了MySQL中使用JSON存儲(chǔ)數(shù)據(jù)的實(shí)現(xiàn)示例,我們可以在MySQL中直接存儲(chǔ)、查詢和操作JSON數(shù)據(jù),具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09
Mysql?InnoDB?的內(nèi)存結(jié)構(gòu)詳情
這篇文章主要介紹了Mysql InnoDB的內(nèi)存結(jié)構(gòu)詳情,InnoDB存儲(chǔ)引擎的邏輯存儲(chǔ)結(jié)構(gòu)是什么呢,下面我們就一起進(jìn)入文章了解更多詳細(xì)內(nèi)容吧,感興趣的小伙伴可以參考一下2022-05-05
mysql8.0.19基礎(chǔ)數(shù)據(jù)類型詳解
這篇文章主要介紹了mysql8.0.19基礎(chǔ)數(shù)據(jù)類型的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2020-03-03

