How to extract database from a whole MySQL database dump with sed

Tuesday, 12th February 2013

If you have a configured mysql dumps to be prepared regularly via cronjob
and you happen to experience crash or lost of data and need to restore only a certain
database from a whole bunch of MySQL data SCRIPT file letes say mysql-fulldump.sql, you might be wondering how.
Here is how:

# sed -n '/^-- Current Database: `DATABASE_NAME`/,/^-- Current Database: `/p' mysql-fulldump.sql > DATABASE_NAME.sql

Change DATABASE_NAME with whatever your required database name is.
mysql-fulldump.sql – is the name of whole database file dump file
DATABASE_NAME.sql – will contain the extracted database from complete SQL dump.
TThat's all, now import new dump to MySQL and Enjoy 🙂

Share this on:

More helpful Articles

Download PDFDownload PDF

Tags: , , ,

Leave a Reply

CommentLuv badge