mysql忘記密碼

如下來自:http://www.cnblogs.com/visoeclipse/archive/2010/04/06/1705427.html

 

MySQL忘記密碼解決方案

破解本地密碼:

 

  Windows:

    1.用系統管理員登陸系統。
    2.停止MySQL的服務。
    3.進入命令窗口,然後進入 MySQL的安裝目錄,比如我的安裝目錄是c:\mysql,進入C:\mysql\bin
    4.跳過權限檢查啓動MySQL,

      c:\mysql\bin>mysqld-nt –skip-grant-tables

      或則:c:\mysql\bin>mysqld –skip-grant-tables

      mysqld.exe是微軟Windows MySQL server數據庫服務器相關程序。
      mysqld-nt.exe是MySQL Daemon數據庫服務相關程序。

 

    5.[未驗證]

      重新打開一個窗口

      進入c:\mysql\bin目錄,設置root的新密碼
      c:\mysql\bin>mysqladmin -u root flush-privileges password "newpassword"
      c:\mysql\bin>mysqladmin -u root -p shutdown

      將newpassword替換爲你要用的root的密碼,第二個命令會提示你輸入新密碼,重複第一個命令輸入的密碼。

    5.[驗證]或則:

      重新開打一個命令提示符的窗口(CMD)

      用空密碼方式使用root用戶登錄 MySQL;
        mysql -u root
      修改root用戶的密碼;
        mysql> update mysql.user set password=PASSWORD('新密碼') where User='root';
        mysql> flush privileges;
        mysql> quit


 

    6.停止MySQL Server,用正常模式啓動Mysql
    7.你可以用新的密碼鏈接到Mysql 了。



Unix&Linux:
    1.用root或者運行mysqld 的用戶登錄系統;
    2.利用kill命令結束掉mysqld的進程;
    3.使用–skip-grant-tables參數啓動MySQL Server
      shell>mysqld_safe –skip-grant-tables &
    4.爲root@localhost設置新密碼

      shell>mysqladmin -u root flush-privileges password "newpassword"5.重啓MySQL Server

 

 

 附錄:

   MySQL修改密碼的方法大全:

 

    mysql> update user set Password=password('newpassword') where User='root';
    mysql> flush privileges;

         MYSQLADMIN -u root -p PASSWORD mypasswd

          可以修改MYSQL文件夾中的MY.INI文件

          mysql> SET PASSWORD FOR myuser@localhost = PASSWORD('mypasswd');

          mysql> GRANT USAGE ON *.* TO myuser@localhost IDENTIFIED BY 'mypassword';

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章