Sometimes we need to do a mysqldump of a database on a remote server, but the server does not have mysqldump installed. I would like to use the mysqldump on my machine to connect to the remote database and do the dump on my machine.
Create an ssh tunnel
ssh -f -L3310:localhost:3306 firstname.lastname@example.org -N
Run Mysqldump Command
mysqldump -P 3310 -h 127.0.0.1 -u mysql_user -p database_name table_name
Do not use localhost ! it’s one of these ‘special meaning’ nonsense that probably connects by socket rather then by port
If host is set to
localhost, a configured (or default)
--socket option is assumed. See the manual for which option files are sought / used. Under Windows, this can be a named pipe.