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

MySQL Root 密碼遺忘快速重置:skip-grant-tables 三步驟法

     編輯:MySQL 資料庫相關知識

適用場景

已知 root 密碼遺失,需在無密碼情況下進入資料庫重設。

步驟(Linux/Unix)

  1. 停止 MySQL:
    killall -TERM mysqld
  2. 啟動跳過權限表:
    bin/mysqld_safe --skip-grant-tables &
  3. 無密碼登入並更新:
    mysql -u root
    USE mysql;
    UPDATE user SET Password=PASSWORD('new_pass') WHERE User='root';
    FLUSH PRIVILEGES;
    QUIT;
  4. 正常重啟 MySQL:
    killall -TERM mysqld && bin/mysqld_safe &

Windows 版本

  1. 服務管理員停止 MySQL 服務。
  2. 命令列啟動:
    mysqld-nt --skip-grant-tables
  3. 另開視窗:
    mysql -u root → 執行相同 UPDATE/FLUSH。
  4. 關閉視窗,服務管理員啟動 MySQL 服務。

安全提醒

  • --skip-grant-tables 期間任何人可無密碼登入且擁有完整權限,務必在內網隔離環境、最短時間內完成。
  • 完成後檢查 user 表無匿名帳號、root 僅允許 localhost/127.0.0.1。
  • MySQL 5.7+ Password 欄位改名為 authentication_string,語法相應調整:
    UPDATE user SET authentication_string=PASSWORD('new_pass') WHERE User='root';
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved