2

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
sam452
  • 1,281
  • 3
  • 20
  • 33
  • Where do you execute the `mysqldump`? – Martin Prikryl Feb 12 '15 at 07:28
  • Yes, good question. In Windows cmd I executed the first command in plink to create the tunnel. It rolled into the Linux host as a ssh command for logging in. So the mysqldump was executed on the linux server. I saw in other SO posts for linux that they used the '-N' flag at the end. Attempting to do that in Windows left the CMD program hanging. So I opened a new CMD window and executed the mysqldump figuring the tunnel was open. I believe there is something missing here. – sam452 Feb 12 '15 at 19:33

1 Answers1

1

You have several options:

  • Dump the database remotely to a remote file and download it to your machine afterwards:

    plink sam@192.168.0.20 "mysqldump -u sam -p --all-databases > outfile.sql"
    pscp sam@192.168.0.20:outfile.sql .
    

    The redirect > is inside the quotes, so you are redirecting mysqldump 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:

    plink sam@192.168.0.20 "mysqldump -u sam -p --all-databases" > outfile.sql
    

    Note that the redirect > is outside of the quotes, comparing to the previous case, so you are redirecting an output of plink, i.e. output of the remote shell, which contains output of a remote mysqldump.

  • Tunnel connection to the remote MySQL database and dump the database locally using a local installation of MySQL (mysqldump):

    plink sam@192.168.0.20 -L 3310:localhost:3306
    

    In a separate local console (cmd.exe):

    mysqldump --port=3310 -h localhost -u sam -p --all-databases > outfile.sql
    

    In this case nothing is running remotely (except for a tunnel end).

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992