mysql 數據庫忘記密碼【轉載】

在windows環境下mysql

1.殺死全部的mysql進程linux

      a.經過dos命令:net start 與net stop mysqlsql

      b.經過控制面板的服務windows

2.在dos的提示框內,將路徑定位到mysql的安裝目錄下如:c:\mysql\binui

     在控制檯輸入:mysqld  --skip-grant-tables    //越過root權限url

     回車後,沒有任何顯示,表示成功spa

3.從新打開一個dos提示框,在框內輸入mysql -u root -p 進行無密碼登錄rest

4.對mysql的密碼進行修改blog

   輸入以下命令進程

    >use mysql 

    >update user set password=password("new_pass") where user="root"; 

    >flush privileges; 

    也能夠這樣:mysqladmin -h hostname -u user password 'new password''。

    在載入權限`mysqladmin -h hostname flush-privileges' ,或者使用 SQL 命令`flush privileges'。 

5.退出

   輸入\q

6.從新進入以新修改的密碼進入mysql



在linux環境下:

  1.終端輸入 vi  /etc/my.cnf

     回車,進入修改,在[mysqld]段中加入

     skip-grant-tables保存退出

   2.重啓mysql的服務

       service mysqld restart

   3.登陸mysql

      終端輸入:mysql回車登陸

      進入mysql後,輸入:

      use mysql;

      update user set password=password('new password') where user='root';

      flush privileges;

      quit;

      退出mysql

   4.再次進入vi  /etc/my.cnf

      修改回原來的狀態,去掉skip-grant-tables,保存退出

   5.重啓mysql服務

        service mysqld restart,用新密碼登陸

轉載url:http://mrhouzhibin.blog.163.com/blog/static/1945962412011926112959446/

相關文章
相關標籤/搜索