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.

aaron carlino
  • 303
  • 3
  • 7

1 Answers1

12

Figured it out:

ssh me@myserver.com mysqldump -u user -ppass remote_db | mysql -u user -ppass local_db
hexacyanide
  • 88,222
  • 31
  • 159
  • 162
aaron carlino
  • 303
  • 3
  • 7
  • 8
    You can make it faster by piping it through compression. Assuming you have bzip on both ends: `ssh me@myserver.com "mysqldump -u username -ppassword remote_db --verbose | bzip2 -c" | bunzip2 -c | mysql -u localuser -plocalpass localdb` – sghael Nov 10 '11 at 15:09
  • Don't forget you should Accept your own answer. Clearly it has helped others. – tw16 Dec 11 '14 at 22:12