Backing up a remote accessible MySQL database

This may seem as a very specific case since it might seem like a bad idea to expose an SQL database to the world wide web. Even though IP-restrictions may apply it may still be accessible to non authorised personell. Of course there’s a trade-off between security and simplicity and thus something like this might come in handy.

In order to make a dump of the MySQL database you want a tool called mysqldump and is located in the mysql-client package in the Debian repositories. The following command will install the package for you. Remember that you need to use sudo or log in as super user.

sudo apt-get mysql-client

Following this you want to utilise the mysqldump tool. A command may look as follows depending on the use and needs.

mysqldump --host hostaddress -u username -ppassword databasename > databasename.sql

The mysqldump tool will output the databasedump to stdout and thus we want to pipe it to a file, in this case named ‘databasename.sql’. Note that the password should follow exactly after the ‘-p’ flag without any spacing.

Leave a Reply