2. 修改.my.cnf中InnoDB的默认配置
配置文件中,InnoDB典型的配置如下:# Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = /home/root/tools/mysql-5.0.80/var/ #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = /home/root/tools/mysql-5.0.80/var/ #innodb_log_arch_dir = /home/root/tools/mysql-5.0.80/var/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 16M #innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size #innodb_log_file_size = 5M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50可见,InnoDB相关的配置默认都是注释掉的,开启并指定新值如下(注:具体的配置值应根据部署机器的物理配置而定):
innodb_buffer_pool_size = 512M innodb_additional_mem_pool_size = 256M innodb_log_file_size = 128M # 注意这里跟默认值不一样! innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 0 # 避免频繁flush innodb_lock_wait_timeout = 50修改完成后,mysql安装路径下执行"./bin/mysqld_safe &",以重启mysql server。shell终端执行ps aux | grep "mysqld"可看到进程已启动。
130701 16:15:20 mysqld started InnoDB: Error: log file /home/root/tools/mysql/var/ib_logfile0 is of different size 0 5242880 bytes InnoDB: than specified in the .cnf file 0 134217728 bytes! 130701 16:15:21 [Note] /home/root/tools/mysql/libexec/mysqld: ready for connections. Version: '5.0.80-log' socket: '/home/root/tools/mysql/var/mysql.sock' port: 3306 Source distribution 130701 16:15:37 [ERROR] /home/root/tools/mysql/libexec/mysqld: Incorrect information in file: './data/tv_KEY_PREDEAL.frm' 130701 16:15:37 [ERROR] /home/root/tools/mysql/libexec/mysqld: Incorrect information in file: './data/tv_KEY_PREDEAL.frm' # 此处省略若干行,均是加载数据表的frm文件失败的Error日志从日志看到,重启mysql server实例时确实发生了错误,log file对不上导致加载InnoDB引擎失败。
3. 最终解决方法
从上面分析可知,我们现在遇到两个错误:
1)mysql命令行抛出的: Error 'Unknown table engine 'InnoDB'' on query.
2)mysql error日志输出:InnoDB: Error: log file /home/root/tools/mysql/var/ib_logfile0 is of different size 0 5242880 bytes
从因果关系看,后者是出错的根本原因,因此,只需解决这个error即可。
根据stackoverflow上的这篇帖子给出的解决方法,执行以下操作:
1)删除mysql数据文件夹下的ib_logfile0和ib_logfile1(更安全的做法是将它们mv备份到其它路径下)
2)重启mysql server
此时,查看mysql启动日志无ERROR,同时,在mysql命令行show engines可看到innodb对应的"Support"一列为YES状态,表明mysql server已经成功加载该引擎,最后,执行SQL查询命令也不再报错。
至此,问题才算彻底解决。
【参考资料】
1. StackOverflow: Unknown table engine 'InnoDB'
2. StackExchange: InnoDB: Error: log file ./ib_logfile0 is of different size
3. MySQL BUG ISSUES - bug about v5.0.22
================ EOF ===============