4
1
My little 5GB database which takes 5 minutes to dump via mysqldump, takes 9 hours to restore. Luckily I found this out during a test-run, not an actual emergency situation.
What are the best parameters to optimize to speed this up?
I have tried the following settings on my server with 2GB of RAM:
innodb_buffer_pool_size=512M
innodb_additional_mem_pool_size=50M
innodb_file_per_table
innodb_flush_method=O_DIRECT
innodb_flush_log_at_trx_commit=0
innodb_log_file_size=1G
innodb_log_buffer_size=1G
The weird thing is that even with these aggressize settings, top
only shows mysqld is barely using a fraction of the assigned memory:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4421 mysql 20 0 247m 76m 5992 S 91 3.7 4:09.33 mysqld
I just want to make sure you are using --opt with the mysqldump utility. This is a HUGE time saver when reloading. without it mysqldump creates the sql file row by row. --opt does: Adds locks, drop and recreate with all create options enabled, temporarily disables the keys for a quick reload and then turns keys back on at the end to rebuild the indexes after the writing is done. It concatenates several rows together in inserts to reduce filesize AND parsing time of each statement (by up to 70%) and enables --quick to reduce the load against the dumping DB when running. reduces load time by 80% – ppostma1 – 2015-08-07T14:18:34.357
@ppostma1 --opt is enabled by default. It says so in the documentation already : http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html#option_mysqldump_opt
– RolandoMySQLDBA – 2015-08-07T14:22:25.230I have 4 different flavors of linux running online servers and some distro's mysql package managers disable it! It can be the different between 12 hours to reload a WP database and 8 minutes when its on. I find the managers explanation is "availability of incremental backups". My best understanding is if the server is routinely backed up, it could be off by default. Then the user must manually add the --opt option to specify this is not an incremental backup attempt. – ppostma1 – 2015-08-14T15:26:51.507
1@ppostma1 Oh that's scary !!! The documentation says it is on by default. My guess is that the distros that do not have
--opt
must have been compiled from source and the option forgotten. I'll definitely keep this issue in my back pocket for any future encounters like this. Thank You. – RolandoMySQLDBA – 2015-08-14T15:38:30.070Some sql files can be awkward to edit and add "SET SQL_LOG_BIN=0;" Instead: echo "SET SQL_LOG_BIN=0;" | gzip > sql_log_bin.sql.gz; then run this: zcat sql_log_bin.sql.gz backup.sql.gz | mysql – Andy Lee Robinson – 2011-07-25T00:16:55.097