Open In App

How to Generate Database Dump of MySQL Database in Linux?

We will learn how to Backup and Restore your MySQL Database with Mysqldump query in LINUX.  We had always a need that if the production database is corrupted somehow, we should be able to recover it, for recovering we should always keep a backup of the database at particular instances. So, data rollback can be done.

First, we will create a Database in our system. We will need LAMPP and APACHE Software for this purpose.



Step 1: Create a database using the below command:

CREATE DATABASE geeksforgeeks;

Step 2: Use the database using the below command:



USE geeksforgeeks;

Step 3: Create a table in this database as shown below:

CREATE TABLE employeeData(ID INT(10),
            Name VARCHAR(255),
            Designation VARCHAR(255),
            Address VARCHAR(255),
            Branch VARCHAR(255)
            );

Step 4: Describe this table to see if it is correctly created or not:

DESC employeeData;

Employee Data Table is successfully created

Step 5: Insert some data in this table.

INSERT INTO `employeedata`(`ID`, `Name`, `Designation`, `Address`, `Branch`) VALUES (1,"Devesh Pratap Singh","Software Engineer","Uttar Pradesh, India", "Noida");
INSERT INTO `employeedata`(`ID`, `Name`, `Designation`, `Address`, `Branch`) VALUES (2,"Megha Arele","Web Developer","Uttar Pradesh, India", "Noida");
INSERT INTO `employeedata`(`ID`, `Name`, `Designation`, `Address`, `Branch`) VALUES (3,"Aditya Srivastava","Research Analyst","Uttar Pradesh, India", "Noida");
INSERT INTO `employeedata`(`ID`, `Name`, `Designation`, `Address`, `Branch`) VALUES (4,"Tanishka Sharma","Jr. Architect","Uttar Pradesh, India", "Noida");
INSERT INTO `employeedata`(`ID`, `Name`, `Designation`, `Address`, `Branch`) VALUES (3,"Divyanshi Upadhyay","Jr. Architect","Uttar Pradesh, India", "Noida");

Step 6: Dump the data for backup for restoring purposes with the below command:

mysqldump -u root -p geeksforgeeks > ~/Desktop/backup_db.sql

After running this command you will get the dumped database on your desktop.

Output File

Article Tags :