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.



How to Create a MySql DataBase using the command line AKA CLI.

If You have CLI access to MYSQL this is the Simplest, and Quickest Method Possible  to create a MySQL database.

The whole thing consists of this —->  CREATE DATABASE ‘your_database_name’;

What you actually type out on the command line or “query window”.


Simple Command for creating a MYSQL database using the command line aka CLI.

Simple Command for creating a MYSQL database using the command line aka CLI.





There, the database named blue has been created. The output should like like the image below.

Successful Output of "CREATE DATABASE blue;"

Successful Output of “CREATE DATABASE blue;”




Now You can start adding tables to Your database.