I'm trying to use plink
on Windows to create a tunnel to a Linux machine and have the dump file end up on the Windows machine. It would appear that this answer would work and is the basis of my question. But trying it out and looking at other answers I find that the dump file is still on the Linux machine. I'm trying this out in my local environment with Windows and Ubuntu 14.04 before moving to production. In Windows 8.1:
plink sam@192.168.0.20 -L 3310:localhost:3306
mysqldump --port=3310 -h localhost -u sam -p --all-databases > outfile.sql
I've tried swapping localhost
in the second with 127.0.0.1
, adding -N
to the tail of the tunnel setup, using one table in the dump command but despite my tunnel, it's as if the first command is ignored. Other answers indicate to add more commands to the script so that I can use pscp
to copy the file. That also means to re-connect to trash this outfile.sql
. Not ideal for getting other dumps on other servers. If that's the case, why use the first command at all?
What am I overlooking? In plink
, the output of the first is to open up the Linux server where I can run the mysqldump
command. But there seems to be ignoring the first command. What do you think?
You have several options:
Dump the database remotely to a remote file and download it to your machine afterwards:
The redirect
>
is inside the quotes, so you are redirectingmysqldump
on the remote machine to the remote file.This is probably the easiest solution. If you compress the dump before downloading, it would be even the fastest, particularly if you connect over a slow network.
Execute
mysqldump
remotely, but redirect its output locally:Note that the redirect
>
is outside of the quotes, comparing to the previous case, so you are redirecting an output ofplink
, i.e. output of the remote shell, which contains output of a remotemysqldump
.Tunnel connection to the remote MySQL database and dump the database locally using a local installation of MySQL (
mysqldump
):In a separate local console (
cmd.exe
):In this case nothing is running remotely (except for a tunnel end).