
在將資料庫轉換為使用 InnoDB 引擎後,我剛剛在 /etc/mysql/my.cnf 中新增了以下幾行。
innodb_buffer_pool_size = 2560M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency = 16
innodb_flush_method = O_DIRECT
但在重新啟動 mysqld 時,它會引發「ERROR 2013 (HY000) at line 2: Lost connection to MySQL server during query」錯誤。 mysql錯誤日誌顯示以下內容
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 268435456 bytes!
100118 20:52:52 [ERROR] Plugin 'InnoDB' init function returned error.
100118 20:52:52 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
100118 20:52:52 [ERROR] Unknown/unsupported table type: InnoDB
100118 20:52:52 [ERROR] Aborting
所以我註解掉了這一行
# innodb_log_file_size = 256M
並且成功重啟mysql。
我想知道mysql錯誤中顯示的“5242880位元組日誌檔案”是什麼?這是該伺服器上 InnoDB 引擎上的第一個資料庫,那麼該日誌檔案是何時何地建立的?在這種情況下,如何在 my.cnf 中啟用 innodb_log_file_size 指令?
編輯
我嘗試刪除 /var/lib/mysql/ib_logfile0 並重新啟動 mysqld 但仍然失敗。現在,它在錯誤日誌中顯示以下內容。
100118 21:27:11 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 256 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200
InnoDB: Error: log file ./ib_logfile1 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 268435456 bytes!
解決
刪除 /var/lib/mysql 中的 ib_logfile0 和 ib_logfile1 後,它現在可以工作了
答案1
InnoDB對其配置極為挑剔;如果有什麼不對勁,它就會放棄並回家。若要變更日誌檔案大小而不遺失資料:
- 恢復您對日誌檔案大小所做的任何設定變更並再次啟動 MySQL。
- 在正在運行的 MySQL 中:SET GLOBALinnodb_fast_shutdown=0;
- 停止MySQL
- 對日誌檔案大小進行配置變更。
- 刪除兩個日誌檔。
- 啟動MySQL。它會抱怨缺少日誌文件,但它會創建它們,一切都會好起來的。