Synch Local DB with Remote Database Table-MySQL

Posted on 2009-05-27
Medium Priority
Last Modified: 2012-05-07

I found this bit of code in perl and it seems to simply run a mysqldump command line:

mysqldump -al -h remote.mysql.server --password=remote_pass --add-drop-table database_name $table \
 | mysql --password=local_pass database_name

My questions are:

1) If I run this command with the parameter will this allow me to synch my local database to the remote one?

2) There is a backslash (\) within this command line. Is this supposed to be in the execution? I'm thinking it should be without the backslash as so:

mysqldump -al -h remote.mysql.server --password=remote_pass --add-drop-table database_name $table | mysql --password=local_pass database_name

3) I'm assuming that pipeline (|) is needed to separate the commands but then I'm not certain.

Any help is appreciated. =)


# This'll sync a table *from* a remote MySQL server.
# Assumes you have mysqldump and mysql on your path
# and that you have remote access to the server.
# local_pass is your local password
# database_name is your database name
# remote_pass is the production server password
# database_name is the database name (shockingly enough).
# remote.mysql.server is the remote server
my $table=shift;
`mysqldump -al -h remote.mysql.server --password=remote_pass --add-drop-table database_name $table \
 | mysql --password=local_pass database_name`;

Open in new window

Question by:Victor Kimura
LVL 40

Accepted Solution

mrjoltcola earned 2000 total points
ID: 24484992
the backslash is there for line continuation, it was a muli-line command, so you are correct, you can concat the lines and skip the \
The | is there to pipe the dump output stream from mysqldump to mysql

In general for a command: proga | progb

proga output is read in for probg's input

mysqldump creates an output format that can be fed into mysql to re-create things

Author Closing Comment

by:Victor Kimura
ID: 31585736
Hi mrjoltcola,

Thanks for the info.


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this article, we’ll look at how to deploy ProxySQL.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question