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.
2 Answers
Take the difference between two 'CREATE DATABASE' using sed
operation
eg
sed -n '/^-- Current Database: `dbname`/,/^-- Current Database: `/p' alldatabases.sql > output.sql
https://stackoverflow.com/questions/2342356/import-single-database-from-all-databases-dump
Restoring a single database from mysql enterprise full backup
-
Thanks! It's definitely what I need! I'll try to use this version of sed for Windows gnuwin32.sourceforge.net/packages/sed.htm Commented Mar 17, 2015 at 8:09
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 https://stackoverflow.com/questions/1876754/split-up-a-mysqldump-file-with-multiple-databases-by-database/4347578#4347578 The script succesfully split my dump into separate files for each database. FYI I was doing this on Windows in command line after installing http://www.activestate.com/activeperl. Here is useful info for beginners: http://learn.perl.org/first_steps/
Hope this information is helpful!