An easy way to select one db dump from multiple db MySQL dump

Posted on

Question :

In an urgent situation another person made a backup of all the databases from my webserver to one *.sql file (MySQL dump). Now I have a ~700 Mb file with about 20 different databases. As I only need one of them to restore at the moment, is there an easy way to select the only part I need (one database)? Of course I can try to simply select the needed text from the *.sql file to perform a query in PHPMyAdmin, but it is not so easy as the file is big.

Answer :

Take the difference between two ‘CREATE DATABASE’ using sed operation


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

Restoring a single database from mysql enterprise full backup

Despite the fact that MySQLRockstar’s answer is undoubtedly correct I haven’t succeed with the sed script. I was my first time doing this, so I needed some more time to experiment and I was in a hurry.

I’ve had some experience with Perl so I succesfully used this approach The script succesfully split my dump into separate files for each database. FYI I was doing this on Windows in command line after installing Here is useful info for beginners:

Hope this information is helpful!

Leave a Reply

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