windows:
1.用系統管理者登陸系統。
2.停止mysql的服務。 打開指令行視窗: net stop mysql
3.進入指令視窗,然後進入mysql的安裝目錄,比如我的安裝目錄是c:mysql,進入c:mysqlbin
4.跳過權限檢查啟動mysql,
c:mysqlbin>mysqld-nt --skip-grant-tables
5.重新打開一個視窗,進入c:mysqlbin目錄,設定root的新密碼
c:mysqlbin>mysqladmin -u root flush-privileges password "newpassword"
c:mysqlbin>mysqladmin -u root -p shutdown
将newpassword替換為你要用的root的密碼,第二個指令會提示你輸入新密碼,重複第一個指令輸入的密碼。
6.停止mysql server,用正常模式啟動mysql ,打開指令行視窗: net start mysql
7.你可以用新的密碼連結到mysql了。
unix&linux:
1.用root或者運作mysqld的使用者登入系統
2.結束mysql服務
sudo /etc/init.d/mysql stop
3.使用--skip-grant-tables參數啟動mysql server
mysqld_safe --skip-grant-tables
4.為root@localhost設定新密碼
mysqladmin -u root flush-privileges password "newpassword"
5.重新開機mysql server