Mysql – Fastest way to move MySQL database to a new system while minimizing downtime

amazon ec2databasemigrationMySQL

I'd like to minimize downtime (during the "cutover" period).

We're running on EC2 with the data on an EBS volume. Is it safe to take a snapshot of the database volume while it's running and use that to restore on the new one or do I need to shut down the old database first?

Best Answer

I would suggest:

  1. Taking a snapshot whilst briefly in read lock with FLUSH TABLES WITH READ LOCK;.
  2. Bring that dataset up on your secondary machine and check consistency.
  3. Setup replication from the old machine to the new.

Then at your cutover point:

  1. Bring down the client facing IP on the old machine (you have a separate one, right?).
  2. Issue FLUSH LOGS; on the old machine.
  3. Ensure the new machine is in sync. 0 seconds behind.
  4. Stop the old machine and double check the last binlog size against the new machine's position.
  5. Issue STOP SLAVE; RESET MASTER; on the new machine.
  6. Bring up the client facing IP on the new machine and arping to ensure the clients see it.

There are a few finer details, such as whether you are a heavy InnoDB user. But that is the general jist.

Related Topic