# systemd
systemctl stop mysqld
# 或 SysV
service mysql stop
# 找不到服務名時
find / -name "mysql.server" # 通常在 /usr/local/mysql/share/mysql/mysql.server
/usr/local/mysql/share/mysql/mysql.server stop
# 找到 mysqld_safe
find / -name "mysqld_safe"
# 啟動 (背景執行)
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking &
--skip-grant-tables:不載入權限表,任意用戶免密登入--skip-networking:僅允許本地 socket 連線,安全性考量mysql -u root
# 進入 mysql> 提示符後
FLUSH PRIVILEGES; -- 5.7+ 必須先執行
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword123!';
-- 或舊版
UPDATE mysql.user SET authentication_string = PASSWORD('NewStrongPassword123!') WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
QUIT;
# 結束跳過權限的進程
pkill mysqld
# 或
killall mysqld
# 正常啟動
systemctl start mysqld
# 或
service mysql start
# 驗證
mysql -u root -p
# 輸入新密碼
net stop mysql
mysqld --skip-grant-tables --skip-networking
# 新開 CMD 視窗
mysql -u root
UPDATE mysql.user SET authentication_string = PASSWORD('newpass') WHERE User='root';
FLUSH PRIVILEGES;
exit
# 關閉 mysqld 視窗 (Ctrl+C)
net start mysql
修改 config.inc.php:
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'NewStrongPassword123!';
$cfg['Servers'][$i]['auth_type'] = 'cookie'; -- 建議 cookie 模式