26 April 2004

MySQL Sync

Posted by Mikhail Esteves under: LAMP; Tips .

To sync tables sitting on an online MySQL server to a local MySQL server…

mysqldump -al -h [remote-host] --password=[passwd] --user=[username] 
  --add-drop-table [db-name] | mysql --user=[username] --password=[passwd]
  -h localhost [db-name]

To sync tables sitting in a local MySQL server to a remote MySQL server…

mysqldump -al --user=[username] --password=[passwd] -h localhost
  --add-drop-table [db-name] | mysql -h [remote-host] --user=[username]
  --password=[passwd] [db-name]


3 Comments so far...

Jon Bridenbaugh Says:

19 September 2005 at 10:15 pm.

I have used this script so many times over the last year it’s not even funny. I have it printed out and hanging next to my desk.

Just wanted to say thanks for putting it up and also to mention a “gotcha” for those of us that write a lot of sql at the command line:

Do NOT use a semicolon at the end of mysqldump commands.

I kept getting “Unknown database ‘foo;’ errors and only after about 10 attempts did I realize my mistake.

dheeraj Says:

7 July 2006 at 12:19 pm.

thanks a lot for giving me the solution..i just run it for a sample database ..its workin!!! i tried a lot and broken my head for sync solutiion… i tried many tools from net … but had some problem in runnin them …
Thanks a lot again…

jenny Says:

6 October 2007 at 2:16 pm.

wow

Leave a Reply

Browse

Photography

Projects

Pages

Calendar

April 2004
M T W T F S S
    May »
 1234
567891011
12131415161718
19202122232425
2627282930  

Categories

www.flickr.com