How to convert MySQL tables from MyISAM to InnoDB

Since InnoDB is more reliable for storing important data and is more efficient with frequent write requests, I will convert MyISAM tables to InnoDB, in old databases, in one of the companies.

Be sure to make a backup copy of the database since data may be lost, and after the conversion, you need to verify whether all the data is in place.

Connect to the MySQL server with any convenient client, for example, in the Ubuntu terminal, this can be done like this:

mysql -u root -p

Let’s make a list of sql queries for converting MyISAM tables to InnoDB (where dbname is the name of the database you need):

SELECT CONCAT('ALTER TABLE ',TABLE_NAME,' ENGINE=InnoDB;') 
 FROM INFORMATION_SCHEMA.TABLES
 WHERE ENGINE='MyISAM'
 AND table_schema = 'dbname';

You should see similar sql queries:

ALTER TABLE table1 ENGINE=InnoDB;
ALTER TABLE table2 ENGINE=InnoDB;

Now it remains to select the database and execute the previously received sql queries:

use dbname;

See also my other MySQL related articles.

Leave a comment

Leave a Reply