Copy MySQL database from remote server to local

Hi All,


I am trying to copy a MySQL database from a remote server to a local server. So far I find that this works in getting the database:


mysqldump -h Host -u dbUsername -pDBPassword | > /path/to/dir/testBackup.sql


It connects to the remote host and dumps a copy of the database locally.


Is there a way to add to that line to take that dumped database and import it to the local machine? I'm trying to backup databases from our hosting partner and import them locally in case our hosting partner goes down.


TIA - Vijay

Posted on Nov 4, 2011 1:00 PM

Reply
5 replies

Nov 7, 2011 8:14 AM in response to MrHoffman

Thanks... So if I were to create a bash script that looked like this:


#!/bin/bash

mysqldump -h Host -u dbUsername -pDBPassword | > /path/to/dir/testBackup.sql

mysqladmin -u dbUsername -pDBPassword create databasename

mysql -u dbUsername -pDBPassword databasename < testBackup.sql


I could do all three steps in the same script? And possibly repeat those steps in the same script for additional backups?

Nov 7, 2011 5:51 PM in response to Vijay-Kumar

Sure. But test it. You'll need to test it regardless, just to make sure it all works.


In general, I usually prefer to have the backup tool create the initial SQL database archive on the primary server, zip it, and to then have the backup server in a trusted network location pull the database archive over to the backup server. (It can then unzip it or process it as needed.) With this, the primary server doesn't have access to the backups, nor to the backup server. This intended to isolate the access that a breach of the primary server might permit.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Copy MySQL database from remote server to local

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.