Tuesday, July 24, 2012

Enable InnoDB in MySQL

For time to time searching in the internet, I finally found a solution for enabling InnoDB in MySQL.
First of all, check your MySQL database if it supports InnoDB or not:


#mysqladmin -u root -p variables |grep have_innodb
Enter password:
| have_innodb                             | NO


Try one more time:


#mysql -u root -p
mysql>show engines\g;


+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
4 rows in set (0.00 sec)



See that, database doesn't support InnoDB.
To make InnoDB work, edit some parameters in /etc/my.cnf


[root@~]# grep innodb /etc/my.cnf
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
#default-storage-engine=innodb
#default-table-type=innodb
innodb_buffer_pool_size = 400M
innodb_additional_mem_pool_size = 40M
innodb_log_file_size = 100M
innodb_log_buffer_size = 4M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_flush_method=O_DIRECT


Make sure some settings like above are set. Don't need to make all value like that, adjust with your need.
MySQL by default support InnoDB actually, but for some reason it cannot be enable due to the problem that MySQL log files are corrupted. Do this to recover log files:
/etc/init.d/mysqld stop
mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak

/etc/init.d/mysqld start
After all, check if your database again by command:


#mysqladmin -u root -p variables |grep have_innodb


The result should be:


Enter password:
| have_innodb                             | YES

No comments:

Post a Comment