Mysql

調整參數後未載入 InnoDB 引擎

  • May 1, 2014

安裝 MySQL-5.1.73 後,我將預設 my-huge.cnf 放入 /etc/my.cnf 並啟動 mysql 服務。它執行沒有任何問題。現在,我在 /etc/my.cnf 文件中調整了一些參數。以下是我更改的參數。

[mysqld]
key_buffer_size = 298M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 50
query_cache_size = 32M
query_cache_limit = 1M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 2

並為 InnoDB 取消註釋這些變數。在預設文件中,即使 INNODB 處於活動狀態,它也被註釋掉。

# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 1127M
innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

現在,為了驗證 InnoDB 是否可用,我執行了show engines命令。但是,InnoDB並未在其中列出。然後,我執行以下命令:

mysql> show variables like '%innodb%';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| have_innodb           | NO    |
| ignore_builtin_innodb | OFF   |
+-----------------------+-------+
2 rows in set (0.00 sec)

mysql> show engines;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance         | NO           | NO   | NO         |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| FEDERATED  | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| ARCHIVE    | YES     | Archive storage engine                                         | NO           | NO   | NO         |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
7 rows in set (0.00 sec)

我無法找到我在哪裡做錯了?你能幫忙嗎?

添加方式,問題已解決但不知道方式是否正確!:

檢查錯誤日誌在這里肯定有幫助。根據錯誤日誌:

InnoDB: Error: data file /var/lib/mysql/ibdata1 is of a different size
InnoDB: 133760 pages (rounded down to MB)
InnoDB: than specified in the .cnf file 128000 pages!
InnoDB: Could not open or create data files.
Then, I commented - #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend 

在此之後,我在錯誤日誌文件中收到以下錯誤消息:

InnoDB: Error: log file /var/lib/mysql/ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 268435456 bytes!
140430 17:13:37 [ERROR] Plugin 'InnoDB' init function returned error.
140430 17:13:37 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
Then, I commented #innodb_log_file_size = 256M By default #innodb_log_file_size = 5M.

現在,我再次啟動 mysql 服務,發現 Innodb 已作為預設引擎載入。

您在錯誤日誌中發現,如果配置文件將 設置為與數據目錄中文件innodb_log_file_size的物理大小不同的大小,則 InnoDB 拒絕啟動。ib_logfile*

原因是在崩潰恢復期間使用了日誌文件。如果 InnoDB 嘗試初始化,但日誌文件的大小可疑,則它們可能是錯誤的文件。InnoDB 決定不嘗試使​​用錯誤的日誌文件進行崩潰恢復,因為應用錯誤的文件可能會不可挽回地損壞您的數據。所以不管你信不信,關閉儲存引擎是最好的結果。

如果 InnoDB 無法啟動,您可以在配置文件中添加另一行以使 mysqld 拒絕啟動:

innodb=force

在 MySQL 5.6 中,他們增加了更多的靈活性,以便 InnoDB 在您更改配置文件條目時調整日誌文件的大小。這是一個更詳細地解釋這一點的部落格:http ://www.mysqlperformanceblog.com/2013/09/05/my-favorite-secret-mysql-5-6-feature/

其他一些提示

引用自:https://dba.stackexchange.com/questions/64252