Windows 下 MySQL 5.1/5.5/5.6/5.7/8.0 通用密碼重置流程:停止服務 → --skip-grant-tables 跳過權限啟動 → 免密登入 → 更新 mysql.user 表 → 刷新權限 → 正常啟動驗證。
net stop mysql 或「服務」管理單元停止。cd "C:\Program Files\MySQL\MySQL Server 5.x\bin"mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.x\my.ini" --console --skip-grant-tablesmysql -uroot -p → 直接 EnterUSE mysql;UPDATE user SET authentication_string=PASSWORD('NewP@ssw0rd') WHERE User='root';authentication_string,5.6 為 Password。FLUSH PRIVILEGES;QUIT;net start mysqlmysql -uroot -pNewP@ssw0rd| 版本 | 密碼欄位 | PASSWORD() 函數 | 備註 |
|---|---|---|---|
| 5.6 | Password | 支援 | |
| 5.7 | authentication_string | 支援 | 5.7.6+ 建議 ALTER USER 'root'@'localhost' IDENTIFIED BY 'pwd'; |
| 8.0 | authentication_string | 移除 | 必須用 ALTER USER 或 SET PASSWORD |
-- 在 skip-grant-tables 模式下
FLUSH PRIVILEGES; -- 必須先執行,否無法修改 user 表
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewP@ssw0rd';
FLUSH PRIVILEGES;
--defaults-file 路徑錯誤或含空格未加引號。FLUSH PRIVILEGES 導致修改不生效。