首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

MySQL 從 MyISAM 遷移至 InnoDB 完整實戰記錄與錯誤排查

     編輯:MySQL 資料庫相關知識

WordPress 預設使用 InnoDB 引擎,若 MySQL 僅啟用 MyISAM 會導致服務異常。本文記錄作者在 Windows 環境下透過安裝精靈切換引擎、遭遇 ib_logfile 尺寸不符、No valid checkpoint 等錯誤,最終透過刪除舊日誌檔案、重啟系統成功完成遷移的完整排查過程。

問題背景

  • 原資料庫僅支援 MyISAM,安裝 WordPress 後頻繁出現 Mysqld-nt.exe 應用程式錯誤、記憶體無法讀取、服務自動停止。
  • 嘗試透過 MySQL Instance Configuration Wizard 切換至「Transactional Database Only (InnoDB)」,卻在 Start Service 階段失敗,錯誤 1067:程序意外中止。

核心錯誤日誌分析

關鍵日誌位於 MySQL安裝目錄\Data\主機名.err:

InnoDB: Error: log file .\ib_logfile0 is of different size 0 52428800 bytes
InnoDB: than specified in the .cnf file 0 10485760 bytes!
[ERROR] Default storage engine (InnoDB) is not available
[ERROR] Aborting

後續刪除 ib_logfile0 重啟,又出現 ib_logfile1 同樣尺寸不符錯誤。

解決步驟總結

  1. 刪除所有舊 InnoDB 日誌與資料檔:
    del ib_logfile0
    del ib_logfile1
    del ibdata1
  2. 重啟作業系統(關鍵步驟,釋放檔案鎖定)
  3. 重新啟動 MySQL 服務,觀察錯誤日誌輸出:
    InnoDB: Log file .\ib_logfile0 did not exist: new to be created
    InnoDB: Setting log file .\ib_logfile0 size to 109 MB
    InnoDB: Progress in MB: 100
    ...
    InnoDB: Started; log sequence number 0 0
    [Note] mysqld: ready for connections.

關鍵心得

  • 配置變更需重啟 OS:單純重啟服務不足,因舊日誌檔可能被系統快取/鎖定。
  • 善用錯誤日誌:.err 檔案是診斷 InnoDB 啟動失敗的首要線索。
  • 備份 my.ini:每次執行精靈都會自動備份舊 my.ini 為 my.ini.timestamp.bak,可快速回滾。
  • InnoDB 資料檔位置:建議獨立磁碟(如 D:\MySQL InnoDB Datafiles),提升 I/O 效能。

遷移後驗證

mysql> SHOW ENGINES;
+--------------------+---------+----------------------------------------------------------------+
| Engine             | Support | Comment                                                        |
+--------------------+---------+----------------------------------------------------------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, foreign keys         |
| MyISAM             | YES     | MyISAM storage engine                                          |
+--------------------+---------+----------------------------------------------------------------+

確認 InnoDB 為 DEFAULT 即遷移成功。

引擎遷移屬於核心架構變更,生產環境務必先在測試環境完整演練,並準備完整備份與回滾方案。本案例展示了從錯誤日誌入手、逐步排除 ib_logfile 尺寸衝突、checkpoint 失效等典型 InnoDB 啟動障礙的標準排查路徑。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved