9

I'm hoping I can use a shell script that will pull a sql dump down from my production site and into my local database. Ideally, I'd like to be able to run something like this:

sync_site example_com example_local

Where the first argument is the production database and the second is the local database. The remote database is always on the same server, behind SSH, with known MySQL credentials.

1 Answer 1

12

Figured it out:

ssh [email protected] mysqldump -u user -ppass remote_db | mysql -u user -ppass local_db
Sign up to request clarification or add additional context in comments.

2 Comments

You can make it faster by piping it through compression. Assuming you have bzip on both ends: ssh [email protected] "mysqldump -u username -ppassword remote_db --verbose | bzip2 -c" | bunzip2 -c | mysql -u localuser -plocalpass localdb
Don't forget you should Accept your own answer. Clearly it has helped others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.