how to mysqldump remote db from local machine

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 user@remote.server -N

Run Mysqldump Command

mysqldump -P 3310 -h -u mysql_user -p database_name table_name

Important Note

Do not use localhost ! it’s one of these ‘special meaning’ nonsense that probably connects by socket rather then by port

Warning Explanation

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.


Leave a Comment