Michael Svanström

developer, photographer

Restoring a single database from a MySQL dump

If you, like me, happen to end up with a mysqldump –all-databases dump file and need to restore a single database, here’s how (replace Target with your database name):

$ sed -n '/^-- Current Database: `Target`/,/^-- Current Database: `/p' -o Target.sql dump.sql

Note the use of -o instead of output redirection (>), since it’s locale independent. If you have seem to have a charset mismatch, say UTF-8 - ISO-8859-1 issues, convert the dump using iconv.

$ iconv -f UTF-8 -t ISO-8859-1 -c -o Target.iso.sql Target.sql