windows環境下,mysql的root密碼丟失後重置方法

  1. 運行窗口輸入 services.msc,檢查mysql服務是否啓動,若是啓動手動中止或輸入mysql

    net stop mysqllinux

    中止msyql服務。sql

  2.  

    打開cmd命令行,使用cd命令進入mysql 的bin目錄數據庫

    cd D:\SOFT_PHP_PACKAGE\mysql\bin\安全

    輸入 mysql所在盤符切換當前目錄ui

    D:this

     
  3.  

    輸入命令spa

    mysqld --console --skip-grant-tables命令行

    註釋:ip

    該命令經過跳過權限安全檢查,開啓mysql服務,這樣鏈接mysql時,能夠不用輸入用戶密碼。  此時已經開啓了mysql服務了!

    這個窗口保留不關閉,而後新打開一個cmd命令窗口。

     
  4.  

    輸入命令:

     

    mysql -u root -p

    鏈接mysql,出現輸入密碼的提示,直接回車使用空密碼便可成功鏈接

     

    Enter password:

     
  5.  

    使用SHOW命令查看數據庫

    SHOW databases;

    使用USE命令切換到mysql數據庫

    USE mysql;

     

    使用UPDATE命令更改root密碼:

     

    UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';

     

    刷新權限:

     

    FLUSH PRIVILEGES;

     

    退出,從新登陸

     

     

    quit

  6. 6

    運行

    net start mysql

    啓動mysql服務 

     

    從新登陸mysql

     

    mysql -u root -p

     

    出現輸入密碼提示,輸入新的密碼便可登陸:

     

    Enter password: ***********

     

     

     

    顯示登陸信息: 成功  一切ok

     

    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 

     mysql> SELECT 1; ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

    mysql> ALTER USER USER() IDENTIFIED BY 'new_password'; Query OK, 0 rows affected (0.01 sec)

    mysql> SELECT 1;

    +---+ | 1 |

    +---+ | 1 |

    +---+ 1

    row in set (0.00 sec)

     

     

    在linux下修改mysql的root的密碼

    先中止mysql

    service mysqld stop

    進入到mysql的安裝目錄 /bin

    以不檢查權限的方式啓動

    mysqld_safe --skip-grant-tables &

    mysql -u root -p

相關文章
相關標籤/搜索