以 --skip-grant-tables 參數啟動 MySQL,暫時繞過權限驗證,以空密碼登入 root,更新 mysql.user 表的 password 欄位,再重啟服務生效。
net stop mysqlbin 資料夾(如 C:\MySQL\bin),啟動跳過權限的執行檔:mysqld-nt.exe --skip-grant-tablesmysqld.exe --skip-grant-tables,視版本而定)mysql 免密登入。USE mysql;
UPDATE user SET password=PASSWORD('新密碼') WHERE User='root';
FLUSH PRIVILEGES;
EXIT;
mysqld-nt.exe 進程。net start mysqlmysql -u root -p新密碼service mysql stop 或 systemctl stop mysqld 或 killall -TERM mysqldmysqld_safe --skip-grant-tables &/usr/bin/mysqld --skip-grant-tables &)mysql -u rootUSE mysql;
UPDATE user SET authentication_string=PASSWORD('新密碼') WHERE User='root';
-- MySQL 5.7+ 欄位名為 authentication_string
FLUSH PRIVILEGES;
EXIT;
killall mysqld 或 service mysql stopservice mysql startauthentication_string,舊版為 password,請先 DESC mysql.user; 確認。SELECT User, Host, plugin FROM mysql.user; 確認無匿名帳號。skip-grant-tables 仍無法登入,檢查 my.cnf 是否有 skip-networking 或 bind-address=127.0.0.1 限制。