Speeding up mysql dumps and imports

MysqlBackupRestore

Mysql Problem Overview


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.

Mysql Solutions


Solution 1 - Mysql

  1. Get a copy of High Performance MySQL. Great book.
  2. Extended inserts in dumps
  3. Dump with --tab format so you can use mysqlimport, which is faster than mysql < dumpfile
  4. Import with multiple threads, one for each table.
  5. Use a different database engine if possible. importing into a heavily transactional engine like innodb is awfully slow. Inserting into a non-transactional engine like MyISAM is much much faster.
  6. Look at the table compare script in the Maakit toolkit and see if you can update your tables rather than dumping them and importing them. But you're probably talking about backups/restores.

Solution 2 - Mysql

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.

Solution 3 - Mysql

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.

Solution 4 - Mysql

I guess your question also depends on where the bottleneck is:

  • If your network is a bottleneck you could also have a look at the -C/--compress flag to mysqldump.
  • If your computer runs out of memory (ie. starts swapping) you should buy more memory.

Also, have a look at the --quick flag for mysqldump (and --disable-keys if you are using MyIsam).

Solution 5 - Mysql

Using extended inserts in dumps should make imports faster.

Solution 6 - Mysql

turn off foreign key checks and turn on auto-commit.

Solution 7 - Mysql

mysqlhotcopy might be an alternative for you too if you only have MyIsam tables.

Solution 8 - Mysql

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)

Solution 9 - Mysql

Another alternative is http://www.mydumper.org - multi-threaded mysql backup/restore which is 3x to 10x times faster than mysqldump and can handle both MyISAM and InnoDB as well as Drizzle http://vbtechsupport.com/1695/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondeadprogrammerView Question on Stackoverflow
Solution 1 - MysqlJBBView Answer on Stackoverflow
Solution 2 - MysqlAlister BulmanView Answer on Stackoverflow
Solution 3 - MysqlAleksandar IvanisevicView Answer on Stackoverflow
Solution 4 - MysqlZtyxView Answer on Stackoverflow
Solution 5 - MysqlcheView Answer on Stackoverflow
Solution 6 - MysqllongneckView Answer on Stackoverflow
Solution 7 - MysqlZtyxView Answer on Stackoverflow
Solution 8 - MysqlpaulView Answer on Stackoverflow
Solution 9 - Mysqlp4guruView Answer on Stackoverflow