How to setup a slave replication of mysql database for development?

Charles Bao :

I've set up a slave replication of MySQL database. And for development requirements, I want to write sth into the slave database, but it would cause the broken of replication.

Since the database is huge, I don't want to restore the slave database from MySQL dump file every time after I finished some development work.

My requirement:

  • All the changes in the slave database can be reverted by a simple command.

  • The replication keeps working.

Bill Karwin :

One method is to use LVM filesystem snapshots. Before you begin testing:

  1. Stop replication.
  2. Take an LVM snapshot.
  3. Do your tests. Replication is still off, but data is up to date

After you finish testing:

  1. Stop mysqld.
  2. Restore the snapshot. This reverts all files to the state they were at the moment you created the LVM snapshot above.
  3. Start mysqld and start replication. It will need to catch up and apply all changes since you stopped replication before your testing. This will take a little while, depending on how many changes happened on your master database.

See https://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-lvm/ for a nice tutorial on using LVM snapshots.

This method only works if your development database instance is on Linux.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=12134&siteId=1