MySQL: Convert a table from MyISAM to InnoDB or vica versa

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 09, 2015

Follow me on Twitter as @mattiasgeniar

This post just shows you the commands to convert a table from MyISAM to InnoDB or from InnoDB to MyISAM. If you don’t know the differences between these storage engines, you probably shouldn’t be changing this.

(tl;dr: row/table locking and full text search behaves differently, on top of a couple of hundred other parameters. If you’re worried about performance, make sure to check innodb_buffer_pool_size (InnoDB) and key_buffer_size (MyISAM) before and after your changes)

Convert a table to MyISAM

If you currently have a table in InnoDB and you’d like to convert it to MyISAM, use the following query. Please note that depending on the size of table, this can take a couple of seconds to a couple of hours to complete.

Consider running this in a screen and schedule downtime for your application.

$ mysql
MySQL> USE your_database_name;
MySQL> ALTER TABLE your_table_name ENGINE=MyISAM;
Query OK, 5 rows affected (0.25 sec)
Records: 5  Duplicates: 0  Warnings: 0

Convert a table to InnoDB

Alternatively, to convert to InnoDB follow these steps.

$ mysql
MySQL> USE your_database_name;
MySQL> ALTER TABLE your_table_name ENGINE=InnoDB;

Query OK, 5 rows affected (0.25 sec)
Records: 5  Duplicates: 0  Warnings: 0

This can take a while, depending on the size of your database.

How to check your current storage engine per table

Use the following query to see which storage engine your table us currently user. Each table in a database can use a different storage engine.

$ mysql
MySQL> USE your_database_name;
MySQL> SHOW CREATE TABLE your_table_name;

CREATE TABLE `your_table_name` (
  `name` varchar(20) DEFAULT NULL,
  ...
) ENGINE=InnoDB DEFAULT CHARSET=latin1

The last line will tell you which Engine that particular table is now using.

Need more reading material? Go for the official and well-documented explanation at dev.mysql.com: 14.5.4 Converting Tables from MyISAM to InnoDB.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.