首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

Windows 下 MySQL Root 密碼重置指南:跳過權限表啟動與更新密碼

     編輯:MySQL 資料庫相關知識

環境

Windows XP / XAMPP (安裝目錄 `D:/xampp`)

步驟

  1. 停止 MySQL 服務
    > net stop mysql
    # 或任務管理員結束 mysqld.exe
  2. 以 --skip-grant-tables 啟動
    > d:
    > cd xampp/mysql/bin
    > mysqld.exe --skip-grant-tables

    此模式**不載入權限表**,可無密碼登入。

  3. 無密碼登入
    > mysql -u root -p
    # 提示密碼直接 Enter
  4. 更新密碼
    > USE mysql;
    > UPDATE user SET Password = PASSWORD('NewStrongPass') WHERE User = 'root';
    > FLUSH PRIVILEGES;
  5. 重啟正常服務
    # 關閉 --skip-grant-tables 進程 (Ctrl+C 或任務管理員)
    > net start mysql

驗證

> mysql -u root -pNewStrongPass
# 成功進入

注意事項

  • `--skip-grant-tables` **極度不安全**,僅在本機短暫操作,完成後**立即重啟正常模式**
  • MySQL 5.7+ `user` 表欄位為 `authentication_string`,語法調整:
    UPDATE user SET authentication_string = PASSWORD('NewPass') WHERE User = 'root';
  • MySQL 8.0+ 推薦 `ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass';`
  • 生產環境**禁止** root 遠程登入,重置後確認 `host` 欄位為 `localhost`

結語

Windows 下透過 `--skip-grant-tables` 繞過權限驗證,三條 SQL 完成 root 密碼重置,全程 < 2 分鐘。記得依版本調整欄位名 (`Password`/`authentication_string`),並儘快恢復正常權限模式。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved