Restoring a single database from a complete MySQL database dump.

The first option is to pass the whole SQL dump to MySQL command line, but restrict it’s operation using the –one-database option.

mysql -u root -p –one-database destdbname < alldatabases.sql

In the above code substitute destdbname with the database name you want to restore, and alldatabases.sql with the name of your full DB backup.

If you would rather just extract the database dump of the single database from the –all-databases dump file, you can do this with sed using this command:

sed -n ‘/^– Current Database: `dbname`/,/^– Current Database: `/p’ alldatabases.sql > output.sql

Where dbname is replaced with the database name of the database to extract, and alldatabases.sql is the name of your dump file. The result will be saved into the file output.sql.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s