Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following is working as expected.

Sending server:

mysqldump db_name tbl_name -d | nc -l 1234

Receiving server:

nc 1234 | mysql -uroot -proot@123 test

When I am dumping to remote server, it takes a lot of time to transfer data. Is it possible to add tar jcf - and tar jxf - in this process.

share|improve this question
up vote 2 down vote accepted


mysqldump db_name tbl_name -d | bzip2 -c | nc -l 1234


nc 101010.114 1234 | bzip2 -cd | mysql -uroot -proot@123 test

(Replace bzip2 with gzip or some other compression program if you want; they all work much the same way in Linux)

There's no reason to use tar; you're just dumping data out of MySQL as a single chunk of text. You're also using nc in what is generally considered a "backwards" way; typically the consumer of the data (mysql in this case) does the listening (but there's no actual difference in operation, it just "feels" weird).

Be warned, though, this method might not actually make anything go faster -- in my experience, the bottleneck in MySQL dumps/loads is MySQL, not the network (unless you're running this over a seriously bandwidth-constrained link).

share|improve this answer

Piping through tar should work just fine.


... | tar -cjf - | ...


... | tar -xjf - | ...

You might want to use "z" instead as it uses gzip compression instead of the more expensive bzip2, but it depends on how fast it works for you.

share|improve this answer
I really don't understand the desire to use tar in this sort of pipeline. There's no actual files involved. – womble Jul 30 '11 at 11:44
# bzip2: Compressed file ends unexpectedly; # error on receiving data – shantanuo Jul 30 '11 at 11:45
@womble Too early in the morning, didn't catch the whole 'lack of file' thing. – sysadmin1138 Jul 30 '11 at 11:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.