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

在 Linux 系統中,若未使用 PASSWORD() 函數直接修改 MySQL root 密碼,會導致 mysql 系統資料庫消失,造成無法正常登入。以下提供標準修復流程。

修復步驟

  1. 編輯設定檔:開啟 my.cnf(或 my.ini),在 [mysqld] 區段加入 skip-grant-tables。
  2. 重啟 MySQL 服務:systemctl restart mysqld(或 service mysql restart)。
  3. 免密碼登入並修復密碼:
    mysql -u root
    UPDATE user SET authentication_string=PASSWORD('新密碼') WHERE User='root';
    FLUSH PRIVILEGES;
    EXIT;
  4. 移除 skip-grant-tables:編輯 my.cnf 註解或刪除該行。
  5. 再次重啟 MySQL,即可使用新密碼正常登入。

注意:MySQL 5.7+ 版本密碼欄位為 authentication_string,舊版為 password。日後修改密碼請務必使用 ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼'; 或 SET PASSWORD = '新密碼'; 等官方語法,避免再次發生此問題。

Copyright © Windows教程網 All Rights Reserved