#cli #mysql

How to take MySQL DB back up from the command line

As you know regular backups of DB for a running site are very important. Most of the hosting providers do this for you, but sometimes its also expected from you to do the same.

The easiest way is to create a Replica of the current DB through the command line and download it.

Below is the command for doing the same. I am assuming that you are already logged in your server through ssh.

Command

mysqldump -u DB_USERNAME -p DB_DATABASE > FILENAME.sql

It will ask for the password but you can handle it.

Moreover, if you want to take backup of particulate tables from the database you have to pass the name of the tables separated by space.

mysqldump -u DB_USERNAME -p DB_DATABASE TABLE_1 TABLE_2 > FILENAME.sql

Feel free to ask in the comment section in case of any doubt.

mohammed-samgan-khan

Hi, I am Samgan, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialise in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.  

I am also the creator of penit.ink, a site which provides young writers with a free hand place to show their creation to the world. Irrespective of the niche, if you write this place is defiantly for you.