Skip to content
Home » MySQL » MySQL Dump Remote to Local

MySQL Dump Remote to Local

First of all, you have to ensure that SSH command utility has been installed, because Windows does not provide it by default.

C:\Users\alex>ssh
'ssh' is not recognized as an internal or external command,
operable program or batch file.

Windows SSH

But, you can download and install OpenSSH for Windows from SourceForge like mine.

After you installed OpenSSH in Windows, you can test the command by this:

C:\Users\alex>ssh
usage: ssh [-1246AaCfghkNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
           [-D port] [-e escape_char] [-F configfile] [-i identity_file]
           [-L port:host:hostport] [-l login_name] [-m mac_spec] [-o option]
           [-p port] [-R port:host:hostport] [user@]hostname [command]

Your SSH is working now.

Let see an example of dumping command as following:

C:\Users\alex>ssh [email protected] "mysqldump -u root -p'local_password' database_name" > C:\Users\alex\Downloads\dump_file.sql
[email protected]'s password:

In the above, we compose a one line command  (marked as red above) for the remote server, SSH will execute the one line command over ssh and then disconnect from the remote server once the execution is completed. The output will be saved as a local file which is C:\Users\alex\Downloads\dump_file.sql in this case.

You can also directly pipe the dump result into the local database running on Windows instead of a dump file.

C:\Users\alex>ssh [email protected] "mysqldump -u root -p'local_password' database_name" | mysql -u root -p"local_password" database_name
Warning: Using a password on the command line interface can be insecure.
[email protected]'s password:

Please note that, SSH make your dumping job localized, so you must use the local password for the local MySQL account (i.e. root@localhost) of the remote server.

Leave a Reply

Your email address will not be published. Required fields are marked *