How to restore single database from whole MySQL database dump?

How to restore single database from whole MySQL database dump?

If you are backed up all the MYSQL databases on server by using –all option and you have to restore single database from entire database backup file. So, don’t get panic you can resolve this resolve and can easily restore single MYSQL database from all the databases.

For the single database you have to use –o option while restoring the database. In this article we are going to explain how to restore particular database from the complete MYSQL database. You just have to enter following command with specified database name which you want to restore.

Code:
mysql -p -o databasename < allmysqldatabases.sql
Here databasename will be the particular database name which you want to restore and allmysqldatabases.sql is the name of the mysql backup file.

Extract the desired database with command:

With the help of sed command you can extract the desired database from the mysql database backup file. Here is the command which you have to use:

Code:
sed -n '/^-- Current Database: ` databasename`/,/^-- Current Database: `/p' allmysqldatabases.sql > db.sql
Through the above command you can easily restore the particular database from the mysql dump file.
Author
bhawanisingh
Views
1,860
First release
Last update
Rating
0.00 star(s) 0 ratings
Top