在 WordPress 專案中,預設使用 InnoDB 儲存引擎以支援交易與外鍵約束。若初期資料庫以 MyISAM 建立,後續遷移至 InnoDB 時常會遭遇服務啟動失敗、記憶體無法讀取等棘手問題。本文詳細記錄一次完整的遷移排查過程,從錯誤日誌分析到最終解決方案,提供實戰參考。
原資料庫使用 MyISAM,安裝 WordPress 並匯入 SQL 均正常。但在新增第二個 WordPress 站點、頻繁存取 phpMyAdmin 後,MySQL 服務頻繁崩潰,錯誤訊息為:
Mysqld-nt.exe 應用程式錯誤:「0x005346c4」指令引用的「0x00786000」記憶體,該記憶體不能為 read…
服務停止後無法重啟,整個資料庫不可存取。
嘗試透過 MySQL Instance Configuration Wizard 將資料庫類型改為支援 InnoDB(選擇「Transactional Database Only」),並指定 InnoDB Tablespace 路徑至 D:\MySQL InnoDB Datafiles。但在 Start Service 階段失敗,錯誤代碼 1067:程序意外中止。
嘗試在 services.msc 手動啟動亦失敗。卸載重裝 MySQL 服務、重啟系統後重新配置,雖然服務啟動成功,但在 Applying Security Settings 階段報錯:ERROR 2003: Can't connect to MySQL server on 'localhost' (10061),顯示 MySQL 實際上仍未正常運行。
錯誤日誌位於 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 後重啟,日誌改為:
InnoDB: Log file .\ib_logfile0 did not exist: new to be created
InnoDB: Setting log file .\ib_logfile0 size to 109 MB
InnoDB: Error: log file .\ib_logfile1 is of different size 0 52428800 bytes
InnoDB: than specified in the .cnf file 0 114294784 bytes!
[ERROR] Default storage engine (InnoDB) is not available
同樣刪除 ib_logfile1 後仍失敗,必須重啟作業系統 才能讓新建的 log file 生效。重啟後日誌顯示:
InnoDB: Cannot initialize created log files because
InnoDB: data files are corrupt, or new data files were created when the database was started previous time but the database was not shut down normally
根據官方文件 Error creating InnoDB 提示,刪除資料目錄下所有 ibdata* 與 ib_logfile* 檔案,再重啟服務。日誌終於出現正常啟動序列:
InnoDB: The first specified data file D:\MySQL InnoDB Datafiles\ibdata1 did not exist: new database to be created!
InnoDB: Setting file D:\MySQL InnoDB Datafiles\ibdata1 size to 10 MB
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: Log file .\ib_logfile1 did not exist: new to be created
InnoDB: Setting log file .\ib_logfile1 size to 109 MB
InnoDB: Progress in MB: 100
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
InnoDB: Started; log sequence number 0 0
[Note] mysqld-nt: ready for connections. Version: '5.0.18-nt' port: 3306
my.ini 中的 default-storage-engine=InnoDB 並設定 innodb_data_file_path、innodb_log_file_size 等參數,避免使用嚮導產生的不穩定配置。ibdata*、ib_logfile*,再啟動服務讓 InnoDB 自動建立乾淨的系統表空間。.err 錯誤日誌,它是診斷 InnoDB 啟動失敗的最直接線索。耗時一天終於完成遷移,也練就了閱讀 InnoDB 錯誤日誌的能力。若初期就依照上述最佳實踐操作,可避開絕大多數坑點。