Using mysqldump to Backup Remote MySQL database using SSH

In this tutorial I will show you how to backup remote MySQL database using SSH.

We are assuming that the remote server uses localhost as hostname. Use the proper host address if the hostname is not localhost.

Step 1: Connect to the Server

Firstly, you need to connect to the remote server. Use the following command to connect to it using a SSH connection.

ssh -f -L3310:localhost:3306 <username>@<servername> -N

For eg. use the following command to connect to using maskaravivek as the user.

ssh -f -L3310:localhost:3306 -N

Step 2: Use mysqldump to Dump Tables

Next, use the mysqldump command to backup your tables.

mysqldump -P 3310 -h -u <user_name> -p <database_name> <table_name> > /Users/vivek/Documents/<filename>.txt

For eg. use the following command to dump StoryTags table from stories_db with stories_admin having the admin previlages.

/usr/local/mysql/bin/mysqldump -P 3310 -h -u stories_admin -p stories_db StoryTags > /Users/vivek/Documents/StoryTags.txt

The screenshot below shows mysqldump being used to dump a MySQL table.

mysqldump using SSH on Mac

This content has been helpful to you?

Thanks for contributing!

Yes No