简体   繁体   中英

How to clone mysql innodb database quickly

We use MySQL(innodb) for storing our data. We have integration tests that spin up mysql database (through docker container) and connect to the DB. We use MyISAM for the test DB(reason explained below).

The way we do is, the first test will load the sql schema into a template DB and subsequent tests will simply clone the DB using file copy. Since MyISAM works fine with file copy, we just copy the entire database directory to a new one, and we have a new cloned DB for each test. This has been working well especially our integration tests run within few seconds.

However, as we add more tests, we continue to discover problems due to differences between InnoDB and MyISAM (index size, foreign key constraint to name few). We want to move the test DB to use InnoDB, but want to keep the speedy clone operation. Doing mysqldump and restore will take 30+ seconds compared to 100ms it takes today.

My question is, is there a way to clone the InnoDB super fast?

One of the faster ways to backup an InnoDB database is with a tool like innobackupex .

You can also image your DB if you FLUSH TABLES first, committing everything to disk in a way that should be consistent if snapshotted. Some services (eg Amazon EC2) allow imaging of running instances that you can later boot up independently or use as a backup restore point.

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