简体   繁体   中英

How to change MyISAM to InnoDB online with out locking table

There are many tables using MyISAM. I have to change their engine to InnoDB; But there are follow difficulties:

1、These tables doesn't have primary key or unique key, so pt-ost tools couldm't add trigger to change it.

2、As they use MyISAM, if I use

“Alter table table_name ENGINE=InnoDB”

or "ADD COLUMN id bigint(10) NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (id)",

the table would be locked for a long time, whick make some features online doesn't work

PS:MySQL version is 5.6.17

You have couple options to done same migration. For example:

  • Create new table like old one.
  • Modify new table as you need.
  • Sync data between new and old tables.
  • Switch rename tables.
  • Re-sync tables again

You need a way to convert MyISAM to InnoDB without locking the table for an extended period of time, and you have no primary key in the table?

Given those constraints, here's a solution:

  1. Create a second database server, and make it a replica of your primary by using a filesystem snapshot .

  2. ALTER TABLE on the replica to convert the table to InnoDB. This will take time on the replica, but it won't impact the primary, because replication is asynchronous.

  3. After the table is converted, replication should resume. Let replication catch up, so the replica is up to date with respect to its primary.

  4. Switch all your apps and clients to use the replica instead of the primary.

Voila! The clients are now using the same table, but it's InnoDB.

Don't write to the former primary anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM