# Linux (systemd)
systemctl stop mysqld
# 或
service mysql stop
# Windows (管理員 CMD)
net stop mysql
# Linux: 後台運行
mysqld_safe --skip-grant-tables &
# Windows: 新開管理員 CMD 窗口運行 (保持窗口不關閉)
mysqld --skip-grant-tables --console
⚠️ **此模式下無密碼可登錄,極度不安全,務必在內網/防火牆保護下操作,完成即關閉。**
# 新終端登錄
mysql -u root
# 進入 MySQL 後執行 (5.7.6+ / 8.0 語法)
UPDATE mysql.user SET authentication_string = PASSWORD('NewPass123!') WHERE User = 'root';
FLUSH PRIVILEGES;
QUIT;
💡 **MySQL 5.7.6 前 / 部分 MariaDB 版本**:
`UPDATE mysql.user SET password = PASSWORD('NewPass123!') WHERE User = 'root';`
# 停止 --skip-grant-tables 進程 (Linux: kill / Ctrl+C; Windows: 關閉 CMD 窗口)
# 正常啟動
systemctl start mysqld
# 或 net start mysql
# 驗證新密碼
mysql -u root -p'NewPass123!'