MySQL root 密碼遺失時,可透過 --skip-grant-tables 啟動略過權限檢查,進入資料庫直接更新 mysql.user 表重置密碼。本文提供 Windows 7 環境完整步驟。
D:\Program Files\MySQL\MySQL Server 5.6net stop mysql 或服務管理器 (services.msc) 停止。cd /d "D:\Program Files\MySQL\MySQL Server 5.6\bin"mysqld --console --skip-grant-tables --shared-memorycd /d "D:\Program Files\MySQL\MySQL Server 5.6\bin"mysql -u rootUPDATE mysql.user SET authentication_string=PASSWORD('NewPass123') WHERE User='root';FLUSH PRIVILEGES;EXIT;--skip-grant-tables 的視窗(Ctrl+C),net start mysql。mysql -u root -pNewPass123authentication_string,5.6 為 Password,SQL 語法請對應版本調整。--shared-memory 避免埠口衝突;若用 TCP 埠口請確保 3306 未被佔用。