在 MySQL 5.1 上,如果 InnoDB 存储引擎在启动期间遇到错误,它可能无法初始化。在这种情况下,它只是禁用 InnoDB 并继续。MyISAM 表可以访问,但 InnoDB 表不能。
检查 InnoDB 存储引擎是否已启用。这是 5.1.65 实例的输出:
mysql> show variables like 'have_innodb';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_innodb | YES |
+---------------+-------+
mysql> show engines;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
. . .
接下来,我通过将 my.cnf 编辑为 set 来模拟 InnoDB 故障,innodb_log_file_size=256M
这不是磁盘上日志文件的大小。然后我重新启动了实例。
mysql> show variables like 'have_innodb';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_innodb | NO |
+---------------+-------+
mysql> show variables like 'innodb%';
Empty set (0.00 sec)
麻烦!去哪里看?错误日志文件:
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 268435456 bytes!
130218 12:50:46 [ERROR] Plugin 'InnoDB' init function returned error.
130218 12:50:46 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
如果在初始化 InnoDB 时遇到错误,您还可以强制 MySQL 中止其启动,这样您就不会再遇到这种情况了。将此添加到 /etc/my.cnf:
[mysqld]
innodb=force
然后当我尝试启动时,我在错误日志中看到:
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 268435456 bytes!
130218 12:55:03 [ERROR] Plugin 'InnoDB' init function returned error.
130218 12:55:03 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
130218 12:55:03 [ERROR] Failed to initialize plugins.
130218 12:55:03 [ERROR] Aborting
130218 12:55:03 [Note] /home/billkarwin/opt/mysql/5.1.65/bin/mysqld: Shutdown complete
在 MySQL 5.5 中,如果 InnoDB 初始化失败,服务器将不会启动。