Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 快速重置 MySQL Root 密碼 (安全模式單機版)

編輯:Linux 教學

針對已忘記 MySQL root 密碼、需單機快速重置的情境,提供最精簡的四步驟操作流程,適用於大多數 Linux 發行版。

操作步驟

1. 停止 MySQL 服務

/etc/init.d/mysql stop
# 或 /etc/init.d/mysqld stop

2. 以跳過權限表模式啟動

/usr/local/mysql/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1 &

注意:mysqld_safe 路徑若不同,請用 find / -name mysqld_safe 確認。

3. 免密登入並重置密碼


/usr/local/mysql/bin/mysql -u root mysql

進入 mysql 提示符後:


UPDATE user SET password=PASSWORD('新密碼') WHERE User='root';
FLUSH PRIVILEGES;
EXIT;

4. 重啟 MySQL 服務


killall mysqld
/etc/init.d/mysql start
# 或 service mysqld start

補充說明

  • 步驟 2 中 & 讓進程在背景運行,>/dev/null 2>&1 抑制輸出。
  • FLUSH PRIVILEGES 必須執行,否則修改不生效。
  • 若 killall mysqld 失效,可用 pkill mysqld 或查詢 PID 後 kill -9。
Copyright © Windows教程網 All Rights Reserved