PHPology is a collective of highly skilled, award winning, web gurus.
Contact Raj on 07985 467 213 or email [email protected]

How to convert all tables from MyISAM into InnoDB?

Today I was playing my current MYSQL database where all 35 the tables where set as MyISAM. Thinking that doing each table 1 at a time would be very annoying for me I search the net to see if there was a quick way to do this and luckily for me, found a neat way of doing it via SQL.

SET @DATABASE_NAME = 'name_of_your_db';
SELECT  CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements
FROM    information_schema.tables AS tb
WHERE   table_schema = @DATABASE_NAME
AND     `ENGINE` = 'MyISAM'
AND     `TABLE_TYPE` = 'BASE TABLE'
ORDER BY table_name DESC;

 

Replace the @DATABASE_NAME value to be your database name.

Run the query and copy the output.

Paste that output as a new SQL query and Run.

All tables should now be converted.

Happy days!