mysqldump backup and restore to remote server

[local-server]# mysqldump -u root -prootpswd db | mysql \
                 -u root -ptmppassword --host=remote-server -C db1

[Note: There are two -- (hyphen) in front of host]

Please note that you should first create the db1 database on the remote-server before executing the following command.


mysqldump --user=username --password=pwd db_name | bzip2 -c > /backup_dir/db_name.sql.bz2

you can embed this part in a script, afterward you can use FTP to transfer to the other location.

To restore, you can

bzip2 -d db_name.sql.bz2
mysql --user=username --password=pwd db_name < db_name.sql

This link provides information on backing up and restoring with mysqldump. It also gives some examples with a remote server.

The important commands from that link being:

backup:

mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

restore:

mysql -u root -p[root_password] [database_name] < dumpfilename.sql