Mysql Backup and Restore Database

Backup of single Database :
Step 1: To take backup of a single Database , use the following command

mysqldump -u [username] -p databasename > backup filename
eg: mysqldump -u root -p sample_db > sample.sql

step 2: To Restore in database , use the following :

create database example_db;
exit;
mysql -u [username] -p databasename < backup filename
eg: mysql -u root -p example_db < sample.sql

step 3: Login as root user and check the databases.

Backup of single table in Database
Step 1: To take backup of single table in database, use the following command

mysqldump -u [username] -p [databasename][tablename] > savefile
eg: mysql -u root -p sample_db Persons > person_backup.sql

step 2: To restore the backup of table in Database ,use the following

mysql -u root -p example_db < person_backup.sql

Step 3: Login as root user and check the table in database.

Backup multiple databases
Step 1: To take backup of multiple databases , use the following command

mysqldump -B -u [username] -p [database1][database2] > save filename
        eg: mysqldump -B -u root -p sample_db example_db > two_db.sql

step 2: To restore databases ,use the follwoing command

mysql -u root -p < two_db.sql

step 3: Login as root user and check the databases.

Leave a Reply

Your email address will not be published. Required fields are marked *