Skip to content

How to Dump a Remote Database over SSH in Windows

First of all, you have to ensure that SSH command utility has been installed, because Windows does not provide it by default.
C:Usersed>ssh
'ssh' is not recognized as an internal or external command,
operable program or batch file.

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:Usersed>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:Usersed>ssh root@db.example.com "mysqldump -u root -p'local_password' database_name" > C:UsersedDownloadsdump_file.sql
root@db.example.com'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:UsersedDownloadsdump_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:Usersed>ssh root@db.example.com "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.
root@db.example.com'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 *