How to backup MySQL Database via SSH

First you log in using your terminal application by typing the flowing SSH command:

ssh yourusername@hostname-or-ipaddress

After that, you will be prompted to enter your password. As you enter your password, the text will be hidden. Next we should switch to the “root” user. You can do so by typing the following in your terminal window:

su – root

You will have to enter a password once more. Now navagate to where you would like to store your MySQL database file. For an example of changing the directory to the “public_html” direcotry, type this:

cd /var/www/html_public

Now you can back up your db here using the following command. This command will backup all of your databases. I also chose to compress them after the pipe “|” as a gzip file. Type the following but be sure to change the user name and password to your info:

mysqldump -u yourusername -p yourpassword –all-databases | gzip >databasebackup.sql.gz

You can also target single database using the following:

mysqldump -u yourUserName -p yourDBName | gzip >databasebackup.sql.gz

You may also like...

1 Response

Leave a Reply