{ 38 comments… read them below or add one }

1 nice November 28, 2006

nice and easy. Thanks

Reply

2 John January 16, 2007

mysql connections can be made securely to a remove server via SSL. Just thought I would mention that as it is an additional option to consider. http://dev.mysql.com/doc/refman/5.0/en/secure-connections.html

Reply

3 joel ferido February 8, 2007

thanks for the informations in here.
it really helped me, a newbie..
thanks..

Reply

4 Raul March 27, 2007

Amazingly Simple :)
Thanks a lot… U saved atleast a couple of hours for me :D

Reply

5 Jason April 26, 2007

I am trying your method to copy database from server A (sqldev100) to server B (sql101). I created a user refresh_oper on B with all privilege on database test. But failed for each of them.
1) I got following error when running mysqldump -urefresh_oper -p -hlocalhost test | mysql -urefresh_oper -p -hsql101 test: Error 2003 (HY000): cannot connect to MYSQL server on ‘sql101′ (111).
mysqldump Got error 32 on write.

I am not sure what is the issue.
2) I got prompted of password for refresh_oper@sql101 when I run mysqldump -urefresh_oper -p -hlocalhost test |ssh refresh_oper@sql101 mysql test.

This appears ssh assume refresh_oper is os user?

Can you help on these?

Thanks.
-Jason

Reply

6 Database June 14, 2007

thank you good article

Reply

7 Sky February 6, 2008

Jason, (I know its about a year later, but this is in case someone else has this problem)
I have had the same problem and its because you have an empty “-p” on both sides of your pipe. You will have to specify the password on at least one them.

Reply

8 Carl May 3, 2008

Great tip! This morning I was doing this process manually step by step. And then I stumbled upon this page – Im learning more and more every day!

Only downside is that I dont have any colleagues to impress as Im alone in the IT dept ;)

Reply

9 Rahul Bodhe July 17, 2008

it is very nice site & very much help ful to me I learned a lot from this website
please send me updated query & resoluation for the same
Regards,
Rahul Bodhe

Reply

10 AbnerQC August 19, 2008

Hello, i was wondering, if it is possible to do a dump from a base i have on a website to my localhost.

In other words, does mysqldump has an address and port parameters?

I looked into mysql manual but didnt find anything, thank you for your help.
=)

Reply

11 Cihan Dogan November 12, 2008

Can’t be better!

Reply

12 Student KMPP November 28, 2008

my friend told me that we also can backup mySQL database in .db extension instead of .sql

as i can read from this page… i can this command in shell

# mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

could you all help me on using command in shell to backup in .db

thanks in advanced

Reply

13 Roman January 7, 2009

Thanks! Good Article!

Reply

14 rapidshare library January 24, 2009

ya you can also use mysqlyog tool to maintain yourdatabase from your pc

Reply

15 Safdar Imam February 10, 2009

Great Article!

Thanks

Safdar Imam

Reply

16 Ryan March 7, 2009

I have a problem that is frustrating the crap out of me…. I’m trying to do a mysqldump to another server (obviously don’t want to keep the backup on the same server)…. I’m trying to do this through PHP like the following:

$remote_backup = “/usr/bin/mysqldump $dbname –opt -h$host -u$user -p$password | gzip -c | ssh user@111.222.333.444 ‘cat > /home/httpd/vhosts/domain.com/backups/2009-03-07-15-13-56.gz’”;
system($remote_backup);

This not working from PHP, however when I run it direct from SSH shell below it works perfectly.

/usr/bin/mysqldump $dbname –opt -h$host -u$user -p$password | gzip -c | ssh user@111.222.333.444 ‘cat > /home/httpd/vhosts/domain.com/backups/2009-03-07-15-13-56.gz’

I setup key authentication so that SSH does not prompt for a password, but it is still not working from PHP.

What am I doing wrong? I’ve spend tons of time searching for this solution…. any help would be greatly appreciated.

Thanks.

/usr/bin/mysqldump $dbname –opt -h$host -u$user -p$password | gzip -c | ssh user@111.222.333.444 ‘cat > /home/httpd/vhosts/domain.com/backups/2009-03-07-15-13-56.gz’

Reply

17 Narendra March 16, 2009

Great Article!!!!!!Thanks alot

Reply

18 xps March 31, 2009

I just want to copy with a where condition for a table ,but the same remote machines databases …….. What to do

Reply

19 vijesh May 20, 2009

Tell me how to copy with out data

Reply

20 SZMysqluser October 6, 2009

We are using jasper reports and moved everything on Server A to Server B and sysadmin wiped out Server A. He did backup all files on Server A first. Now the developer wants the db from Server A restored (the jasper tables). Could we take the .frm files from the database directory and replace the ones on Server B with the ones from Server A? This was an application we didn’t know used mysql so we didn’t back anything up using mysqldump. Thanks.

Reply

21 thesql! October 14, 2009

xps:

use mysqldump’s -w switch to specify where
-w “dateColumn > ’2009-10-06′”

Reply

22 Mr. The plague October 14, 2009

This needs to be:

mysqldump -u root –password=pwordhere puaSite | ssh paul@140.203.210.11 mysql -u root –password=pwordhere puaSite

If you are prompted for passwords

Reply

23 Anupam November 26, 2009

This was really helpful and thanks.

Reply

24 namrata January 28, 2010

really nice ya…

Reply

25 amit February 26, 2010

how cane get my sql backup on my server to another pc.

Reply

26 Henno September 16, 2010

I’m using exactly this to export live database to development server. Recently it has started to fail:

root@mybox:~# mysqldump -q -u root -psecret1 –add-drop-database mydb | gzip -c | ssh root@dev.local “gunzip | mysql -u root -psecret2 mydb”
root@dev.local‘s password:
{{{ a few minutes of silence, then: }}}
mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `cache` at row: 4004

Reply

27 Ray March 31, 2011

mysqldump -u user -p db-name > db-name.out
After this command, I can’t find the db-name.out in any directory,
where is it?

Reply

28 Ray March 31, 2011

mysqldump -u user -p db-name > db-name.out
After this command, I can’t find the db-name.out in any directory,
where is it?

Reply

29 omkar yadav April 21, 2011

hi i m omkar yadav your website is very nice and very powerfull
this website is my lucky website

thank you.
omkar yadav

Reply

30 Henno April 21, 2011

Fix to Error 2013: Lost connection to MySQL server during query when dumping table:

mysqldump -q -u root -pMYSQLROOTPASSWORD –max-allowed-packet=256M –add-drop-database MYDB | ssh root@mydevmachine.local “cat – > /tmp/tmp.sql;mysql -u root -pDEVMYSQLROOTPASSWRD MYDB < /tmp/tmp.sql"

Not as fast but very reliable.

Reply

31 francis June 22, 2011

Great – thanks for a nicely written guide.
It wokred an absolute treat!

Reply

32 Arin July 15, 2011

Nice! worked perfectly!

Reply

33 Vab Media July 27, 2011

This finally helped me figure out how to dump the stuff I needed into the remote database. There was stuff I looked at before, but you finally explained it correctly.
Thanks!!

Reply

34 Bob September 15, 2011
35 Random September 15, 2011

You can pipe it locally using
“ssh removemachine command > pipe.out”

Reply

36 Aze October 11, 2011

Thanks. Great snippets!

Reply

37 remotewtf December 6, 2011

what the hell does user@remote.box mean? you’re sending it to his server’s email??? why can’t u linux pèople speak in simpler terms?

Reply

38 remotewtf December 6, 2011

what i mean is i wanted to copy a mysql database to another domain, and now yet again i will fail because you linux ppl don’t speak in moron friendly terms.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 5 + 8 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: