Synch Local DB with Remote Database Table-MySQL


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

Victor KimuraSEO, Web DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Victor KimuraSEO, Web DeveloperAuthor Commented:
Hi mrjoltcola,

Thanks for the info.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.