動態載入 InnoDB 插件或重啟 MySQL 時遇到 Plugin 'InnoDB' registration as a STORAGE ENGINE failed,錯誤日誌提示 log file creation failed。根因是先前卸載 InnoDB 時殘留 ib_logfile* 紅日誌檔案,重新載入時檔案已存在且尺寸/校驗不匹配導致初始化失敗。
InnoDB: If this error appears when you are creating an InnoDB database,
InnoDB: the problem may be that during an earlier attempt you managed
InnoDB: to create the InnoDB data files, but log file creation failed.
InnoDB: Please refer to https://dev.mysql.com/doc/refman/5.1/en/error-creating-innodb.html
131017 0:45:52 [ERROR] Plugin 'InnoDB' init function returned error.
131017 0:45:52 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
# 進入 MySQL 數據目錄 (datadir)
cd /var/lib/mysql # 或 my.cnf 中 datadir 指定的路徑
# 刪除殘留的紅日誌檔案
rm -f ib_logfile*
# 重新嘗試載入 InnoDB (動態)
# mysql> INSTALL PLUGIN InnoDB SONAME 'ha_innodb.so';
# 或直接重啟 MySQL 服務 (推薦)
systemctl restart mysqld
ib_logfile0, ib_logfile1...) 為循環寫入的重做日誌,啟動時需根據 innodb_log_file_size、innodb_log_files_in_group 建立/驗證檔案。ibdata1 系統表空間)。systemctl stop mysqld 並驗證進程消失)。tar czf /backup/mysql_$(date +%F).tar.gz /var/lib/mysql。ib_logfile*,**切勿刪除 ibdata1、ib_buffer_pool、*.ibd 表空間檔案**。my.cnf 中 innodb_log_file_size、innodb_log_files_in_group 設定合理(建議 1G、3-4 組)。InnoDB: Log file ./ib_logfile0 did not exist: new to be created 並成功啟動。| 錯誤訊息 | 原因 | 處理 |
|---|---|---|
| InnoDB: Error: log file ./ib_logfile0 is of different size | 配置 innodb_log_file_size 變更,舊檔案尺寸不符 | 同樣刪除 ib_logfile* 重啟 |
| InnoDB: Cannot open datafile ./ibdata1 | 系統表空間檔案遺失或權限錯誤 | 檢查 datadir 權限、從備份恢復 ibdata1 |
| InnoDB: Operating system error number 13 | 檔案權限拒絕 (Permission denied) | chown -R mysql:mysql /var/lib/mysql |
最佳實踐: 任何涉及 InnoDB 日誌檔案尺寸/數量變更的操作,標準流程為:停庫 → 備份 → 刪除 ib_logfile* → 修改配置 → 啟庫。切勿嘗試在線修改日誌檔案尺寸。