Mysql – How do convert a 66,862,521 row table from MyISAM to InnoDB without going offline for several hours

innodbMySQL

is it possible (and how) to convert a huge MyISAM table into InnoDB without taking the application offline. It requires to insert a couple of rows into that table every second but it is possible to suspend it for about 2 minutes.

Obviously ALTER TABLE … engine=innodb will not work. Therefor I had the plan to create a new table with the innodb engine and copy the content into it. And in the end, suspend the application log thread and RENAME TABLE.

Unfortunately even doing the copying in small batches of 100 rows generates significant lag after some time.

Edit: Existing rows are never changed, this table is used for logging.

Best Answer

Create a Master-Master setup as follows:

  • Create second master, MasterB
  • MasterB acts as slave to logTable
  • Create logTable_new as innodb
  • Run INSERT INTO logTable_new SELECT * FROM logTable (psuedocode) on MasterB, which sends the replication over to MasterA
  • When logTable_new on MasterA finishes syncing, swap out the tables