MYSQL8.0+ 忘記Root密碼:
- 1. 以超級管理者打開cmd,關閉mysql服務
- 2. 跳過權限驗證登入mysql
- 3. 在新的視窗中登入mysql
- 4. 切換到mysql,将密碼置空。
- 5. 設定加密規則并更新新密碼,授權
- 6. 設定成功後,重新開機mysql服務,使用新密碼登入
- 異常:
- Authentication plugin 'caching_sha2_password' cannot be loaded
- The MySQL server is running with the --skip-grant-tables
1. 以超級管理者打開cmd,關閉mysql服務
win10 直接左下角右鍵win徽标,選擇
Windows PowerShell(管理者)
如果沒有配置環境變量,則需要切換到mysql的安裝目錄下,進行關閉mysql服務。
輸入
net stop mysql
2. 跳過權限驗證登入mysql
輸入:
mysqld --shared-memory --skip-grant-tables
此時指令提示符視窗處于鎖定狀态,我們重新以管理者權限打開新的指令提示符視窗。
3. 在新的視窗中登入mysql
使用指令:
mysql -uroot -p
,無需輸入密碼,直接回車即可。
4. 切換到mysql,将密碼置空。
use mysql;
update user set authentication_string='' where user='root';
将authentication_string置空。
然後重新整理權限:
flush privileges;
5. 設定加密規則并更新新密碼,授權
ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc123456' PASSWORD EXPIRE NEVER;
alter user 'root'@'localhost' identified by 'abc123456';
grant all privileges on *.* to "root"@'localhost';
flush privileges;
這裡強調一下,授權的必要性,因為不是首次安裝,是以重置密碼之後原來的權限可能會失效了,比如我這裡就是,在登陸之後,使用
use mysql
,提示沒有權限。導緻後面無法建立使用者,和Navicat連接配接失敗也無法修改。
6. 設定成功後,重新開機mysql服務,使用新密碼登入
重新開機服務,也是需要管理者身份運作cmd,否則沒權限。
異常:
Authentication plugin ‘caching_sha2_password’ cannot be loaded
使用Navicat 連接配接報錯:
Authentication plugin 'caching_sha2_password' cannot be loaded:
加密規則并更新使用者密碼即可。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc123456' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'abc123456';
flush privileges;
The MySQL server is running with the --skip-grant-tables
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement