Are there any documented techniques for speeding up mySQL dumps and imports?
This would include my.cnf settings, using ramdisks, etc.
Looking only for documented techniques, preferably with benchmarks showing potential speed-up.
Are there any documented techniques for speeding up mySQL dumps and imports?
This would include my.cnf settings, using ramdisks, etc.
Looking only for documented techniques, preferably with benchmarks showing potential speed-up.
Assuming that you're using InnoDB...
I was in the situation of having a pile of existing mysqldump output files that I wanted to import in a reasonable time. The tables (one per file) were about 500MB and contained about 5,000,000 rows of data each. Using the following parameters I was able to reduce the insert time from 32 minutes to under 3 minutes.
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
innodb_flush_method = O_DIRECT
You'll also need to have a reasonably large innodb_buffer_pool_size
setting.
Because my inserts were a one-off I reverted the settings afterwards. If you're going to keep using them long-term, make sure you know what they're doing.
I found the suggestion to use these settings on Cedric Nilly's blog and the detailed explanation for each of the settings can be found in the MySQL documentation.
http://www.maatkit.org/ has a mk-parallel-dump and mk-parallel-restore
If you’ve been wishing for multi-threaded mysqldump, wish no more. This tool dumps MySQL tables in parallel. It is a much smarter mysqldump that can either act as a wrapper for mysqldump (with sensible default behavior) or as a wrapper around SELECT INTO OUTFILE. It is designed for high-performance applications on very large data sizes, where speed matters a lot. It takes advantage of multiple CPUs and disks to dump your data much faster.
There are also various potential options in mysqldump such as not making indexes while the dump is being imported - but instead doing them en-mass on the completion.
If you are importing to InnoDB the single most effective thing you can do is to put
innodb_flush_log_at_trx_commit = 2
in your my.cnf
, temporarily while the import is running. You can put it back to 1
if you need ACID.
Make sure you are using the --opt
option to mysqldump when dumping. This will use bulk insert syntax, delay key updates, etc...
If you are ONLY using MyISAM tables, you can safely copy them by stopping the server, copying them to a stopped server, and starting that.
If you don't want to stop the origin server, you can follow this:
But I'm pretty sure your copy-to server needs to be stopped when you put them in place.
I guess your question also depends on where the bottleneck is:
-C
/--compress
flag to mysqldump
.Also, have a look at the --quick
flag for mysqldump
(and --disable-keys
if you are using MyIsam).
Using extended inserts in dumps should make imports faster.
There is an method for using LVM snapshots for backup and restore that might be an interesting option for you.
Instead of doing a mysqldump, consider using LVM to take snapshots of your MySQL data directories. Using LVM snapshots allow you to have nearly real time backup capability, support for all storage engines, and incredibly fast recovery. To quote from the link below,
"Recovery time is as fast as putting data back and standard MySQL crash recovery, and it can be reduced even further."
http://www.mysqlperformanceblog.com/2006/08/21/using-lvm-for-mysql-backup-and-replication-setup/
mysqlhotcopy
might be an alternative for you too if you only have MyIsam tables.
Using indexes but not too much, activate query cache, using sphinx for big database, here is some good tips http://www.keedeo.com/media/1857/26-astuces-pour-accelerer-vos-requetes-mysql (In French)