好長時間沒有用MySQL了,也忘記了當時的root密碼,看了好幾篇文章,把自己的方法記下。
Windows下的忘記root密碼的解決方法:
1、首先先檢查一下MySql服務有沒有打開。可以命令行里面輸入 taskkill /f /im mysqld-nt.exe 先關閉MySql服務 。或者在計算機->管理>服務和應用程序里面的服務,找到mysql服務關閉。再或者也可在windows的任務管理器里面結束掉mysqld.exe 進程。
2、打開一個cmd窗口,切換到mysql的bin目錄
C:/PRogram Files/MySQL/MySQL Server 5.5/bin>,運行命令:
mysqld --defaults-file="C:/ProgramData/MySQL/MySQL Server 5.5/my.ini" --console --skip-grant-tables
(這里注意,新版本的mysql的my.ini在ProgramData里面,網上的多數經驗都寫的在program files里)
注釋:
該命令通過跳過權限安全檢查,開啟mysql服務,這樣連接mysql時,可以不用輸入用戶密碼。
"C:/ProgramData/MySQL/MySQL Server 5.5/my.ini"指配置文件my.ini,一般在mysql安裝目錄里面。
如: 見圖1
========================================================C:/Program Files/MySQL/MySQL Server 5.5/bin>mysqld --defaults-file="C:/ProgramData/MySQL/MySQL Server 5.5/my.ini" --console --skip-grant-tables170208 16:39:51 [Note] mysqld (mysqld 5.5.46-log) starting as process 14276 ...
3、打開第二個cmd窗口,連接mysql: (這里需要說明一下可以輸入命令,也可以直接 開始 - 程序 - mysql server5.5 - MySQL 5.5 Command Line Client)
輸入命令:mysql -uroot -p
出現:
Enter passWord:
這里直接回車,不用輸入密碼。然后就會出現登錄成功的信息,
Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 4Server version: 5.5.46-log MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql>
==============================================
使用命令切換到mysql數據庫:
use mysql;
使用命令更改root密碼:
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
PS:newpassword=你將要修改的密碼
刷新權限:
FLUSH PRIVILEGES;
然后退出,再次登錄:
quit
重新登錄:
mysql -uroot -p
出現輸入密碼提示,輸入新的密碼即可:
如:
Enter password: ***Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 4Server version: 5.5.46-log MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql>
=======================================================
進行到這里就算修改成功啦。
接下來把cmd窗口關閉,再次打開服務即可。
新聞熱點
疑難解答