JellicleCat JellicleCat - 1 year ago 198
MySQL Question

Automate MySQLdump to local computer (Windows)

I'd like to automate a mysqldump to my computer from a remote host, and I cannot figure out how to do it.

I suppose that I should run a mysqldump through an SSH tunnel, but this becomes complicated by the fact that my local computer is a Windows XP machine. I'm using putty to open a tunnel like so:

putty -load "[my saved session]" -L [localport]:localhost:3306 -N

Note: I can't just connect to the mysql server remotely.

Answer Source

Instead of PuTTY, download the command line version plink.exe. Then using the same connection parameters you can run the mysqldump via plink and save the output locally. PLink is available from the same download page as PuTTY.

# setup the tunnel with plink
plink -load "[my saved session]" -L [localport]:localhost:3306
# Mysqldump your local port, redirected to outfile
mysqldump --port=[localport]  -h localhost -uuser -ppassword dbname > outfile

Or, another method would be to execute mysqldump in the same command line as plink, redirecting it to outfile on the local machine.

plink -load "[my saved session]" mysqldump -uuser -ppassword dbname > outfile