Mysql – changing theSQL (5.6) database from MyISAM to InnoDB

innodbmyisamMySQL

I have recently upgraded my CPanel server from mySQL 5.5 to mySQL 5.6 as it now supports full-text searches for InnoDB. Now, I'm not so great at mySQL so I was wondering is there anything special I need to keep in mind other than running

ALTER TABLE my_table ENGINE=InnoDB;

Several of my tables have full text indexes. What will happen to them? Will the indexes be automatically converted? Or do I have to re-build them manually afterwards?

Best Answer

If you do not change any of the FULLTEXT startup parameters, your conversion from MyISAM to InnoDB will take care of creating the FULLTEXT indexes for InnoDB.

CONVERSION STEPS

If you can connect to MySQL from a command-line interface, run this query

SELECT DISTINCT table_schema,table_name
FROM information_schema.statistics WHERE index_type='FULLTEXT';

This will give you every table that has a FULLTEXT index.

Using that query, run this query

SELECT CONCAT('ALTER TABLE ',B.table_schema,'.',B.table_name,' ENGINE=InnoDB') Cmd
FROM (SELECT DISTINCT table_schema,table_name
FROM information_schema.statistics WHERE index_type='FULLTEXT') A
INNER JOIN information_schema.tables B USING (table_schema,table_name)
WHERE B.engine='MyISAM';

This will show you all the commands to convert MyISAM tables with FULLTEXT indexes into InnoDB.

You can dump the commands to a text file.

SQL="SELECT CONCAT('ALTER TABLE ',B.table_schema,'.',B.table_name,' ENGINE=InnoDB')"
SQL="${SQL} FROM (SELECT DISTINCT table_schema,table_name"
SQL="${SQL} FROM information_schema.statistics"
SQL="${SQL} WHERE index_type='FULLTEXT') A"
SQL="${SQL} INNER JOIN information_schema.tables B"
SQL="${SQL} USING (table_schema,table_name)"
SQL="${SQL} WHERE B.engine='MyISAM'"
mysql -uroot -p -ANe"${SQL}" > ConversionScript.sql
less ConversionScript.sql

This will create the conversion script and let you view it.

If you are satisfied with the content of the scripts, log in to mysql and run this:

mysql> source ConversionScript.sql

Give it a Try !!!