Extracting a Single Database From a mysqldump File containing –all-databases Dump.

Imagine to have a full MySQL DB Dump (containing a lot of Single Database Dumps) and imagine also to need the extraction or restoration of a single one. This is a quite common task that can be accomplished using some shell commands.

1. Using the mysql command line client’s –one-database option:

mysql -u root -p --one-database\
 DB_To_Be_Restored < FullDump_File.sql

2. Using ‘sed’ to extract the Dump from the dump file:

sed -n \
'/^-- Current Database: `DB_To_Be_Restored`/,/^-- Current Database: `/p' \
FullDump_File.sql > DB_To_Be_Restored.sql

Comments are closed.