Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between -C and gzipping a mysqldump?

I want to do a mysqldump directly to my remotehost. I've seen suggestions to use the -c switch or use gzip to compress the data on the fly (and not in a file). What's the difference between the two? How do I know if both machines support the -C switch? How would I do a gzip on the fly? I am using linux on both machines.

mysqldump -C -u root -p database_name | mysql -h other-host.com database_name
like image 412
user_78361084 Avatar asked Feb 11 '11 03:02

user_78361084


People also ask

What is the difference between Mysqldump and Mysqlpump?

mysqlpump is the 4th fastest followed closer by mydumper when using gzip. mysqldump is the classic old-school style to perform dumps and is the slowest of the four tools. In a server with more CPUs, the potential parallelism increases, giving even more advantage to the tools that can benefit from multiple threads.

What is Mysqldump used for?

4 mysqldump — A Database Backup Program. The mysqldump client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data. It dumps one or more MySQL databases for backup or transfer to another SQL server.

Does Mysqldump compress data?

By default MySQL Shell Dump & Load utility provides a very good compression algorithm that can save you a lot of disk space. Additionally, with it's parallelism, the Load & Dump is much faster than the traditional mysqldump.

Does Mysqldump create database?

Without this option, mysqldump treats the first name as a database name and those following as table names. With --all-databases or --databases , mysqldump writes CREATE DATABASE and USE statements prior to the dump output for each database.


1 Answers

The -C option uses compression that may be present in the MySQL client-server protocol. Gzip'ing would use the gzip utility in a pipeline. I'm pretty sure that the latter would not do any good since the compression and uncompression would occur on the same machine in this case. If the machine that you are dumping from is local, then the -C option is probably just wasting CPU cycles - it compresses the protocol messages between mysqldump and the mysqld daemon.

The only command pipeline that might make sense here is something like:

mysqldump -u root -p database_name | mysql -C -h other-host -Ddatabase_name -B

The output of mysqldump is going to the pipeline which the mysql command-line client will read. The -C option tells mysql to compress the messages that it is sending to other-host. The -B option disables buffering and interactive behavior in the mysql client which might speed things up a little more.

It would probably be faster to do something like:

mysqldump -u root -p database_name | gzip > dump.gz
scp dump.gz user@other-host:/tmp
ssh user@other-host "gunzip /tmp/dump.gz | mysql -Ddatabase_name -B; rm /tmp/dump.gz"

Provided that you have SSH running on the other machine anyway.

like image 59
D.Shawley Avatar answered Sep 24 '22 01:09

D.Shawley