D:\Program Files\MySQL\MySQL Server 5.6)D:
cd "D:\Program Files\MySQL\MySQL Server 5.6\bin"
net stop mysql
mysqld --console --skip-grant-tables --skip-networking
--console:前台運行,輸出日誌到當前視窗 (**不可關閉此視窗**)。--skip-grant-tables:跳過權限表,免密登入。--skip-networking:禁用 TCP/IP,**防止外部入侵**,極重要!D:
cd "D:\Program Files\MySQL\MySQL Server 5.6\bin"
mysql -uroot -p
# 提示密碼直接按 Enter (空密碼)
-- MySQL 5.7 / 8.0
FLUSH PRIVILEGES; -- 必須先執行!
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPass123!';
-- 8.0 若報錯插件問題
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewStrongPass123!';
-- MySQL 5.6 (舊版)
USE mysql;
UPDATE user SET password = PASSWORD('NewStrongPass123!') WHERE user = 'root';
FLUSH PRIVILEGES;
EXIT;
# 回到第一個視窗,Ctrl+C 停止 mysqld
net start mysql
# 或服務管理器啟動
mysql -uroot -p'NewStrongPass123!' -e "SELECT VERSION();"
mysqld --skip-grant-tables (保持開啟),一個操作 mysql 客戶端。skip-grant-tables 下**必須**手動執行,否則修改不持久化。caching_sha2_password,舊客戶端需指定 mysql_native_password。systemctl stop mysqld
mysqld_safe --skip-grant-tables --skip-networking &
mysql -uroot
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass';
mysqladmin -uroot -p'NewPass' shutdown
systemctl start mysqld
Windows 下 mysqld --console --skip-grant-tables --skip-networking + 雙視窗操作 + FLUSH PRIVILEGES + ALTER USER,三分鐘搞定 Root 密碼重置,安全又可靠。