What's the fastest way to import a large mysql database backup?

守給你的承諾、 提交于 2019-12-04 10:03:55

It depends on how you define "fastest".

As Joel says, developer time is expensive. Mysqldump works and handles a lot of cases you'd otherwise have to handle yourself or spend time evaluating other products to see if they handle them.

The pertinent questions are:

How often does your production database schema change?

Note: I'm referring to adding, removing or renaming tables, columns, views and the like ie things that will break actual code.

How often do you need to put production data into a development environment?

In my experience, not very often at all. I've generally found that once a month is more than sufficient.

How long does mysqldump take?

If it's less than 8 hours it can be done overnight as a cron job. Problem solved.

Do you need all the data?

Another way to optimize this is to simply get a relevant subset of data. Of course this requires a custom script to be written to get a subset of entities and all relevant related entities but will yield the quickest end result. The script will also need to be maintained through schema changes so this is a time-consuming approach that should be used as an absolute last resort. Production samples should be large enough to include a sufficiently broad sample of data and identify any potential performance problems.

Conclusion

Basically, just use mysqldump until you absolutely can't. Spending time on another solution is time not spent developing.

Consider using replication. That would allow you to update your copy in real time, and MySQL replication allows for catching up even if you have to shut down the slave. You could also use a parallell MySQL instance on your normal server that replicates the data to a MyISAM table, which supports online backup. MySQL allows for this as long as the tables have the same definition.

Another option that might be worth looking into is XtraBackup from renowned MySQL performance specialists Percona. It's an online backup solution for InnoDB. Haven't looked at it myself, though, so I won't vouch for it's stability or that it's even a workable solution for your problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!