How To Backup a MySQL Database using the Command Line aka CLI

The fastest, and most reliable way to backup a MySQL database will always be the bulit-in mysqldump utility. This does require shell access to Your database server.

The command is simple.

mysqldump -u “username” -p “database to be backed up” > “backup file name”

What You would actually enter on the command line.

This will open mysql as my user, then ask for my password.  As long as my user has the correct password and permissions, MySQL will backup the database named blue into my home directory, in a plain text file called blue.sql.

In the image below I have added “-v” to show exactly what is happening when You run the command.

The Output from "mysqldump -u -p blue > /home/dave/blue.sql"

The Output from “mysqldump -u -p blue > /home/dave/blue.sql”

 

*****NOTE:  This file is a PLAIN TEXT Backup. That means anyone with access to the file will be  able to be read anything in the database backup without the added security controls of MySQL.  Do NOT leave these plain text backup files anywhere on Your database server.  store them securely outside the database server.

 

 

Leave a Reply

Your email address will not be published.