ABu
ABu

Reputation: 12299

Recover specific database from `-all-databases` mysql dump

Just as the title says, after a complete mysql backup:

mysqldump -uuser -ppass --all-databases > all-dbs.sql

how can I restore only a specific database from that dump? Something like?

mysql -uuser -ppass --restore-db-from-alldbs-backup specific_db < all-dbs.sql

Upvotes: 2

Views: 779

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562721

There's no tool provided with MySQL that does this automatically.

The example below outputs the test database but skips others.

awk 'BEGIN { do_print=1; } \
    /^CREATE DATABASE/ || /^USE / { \
        if (match($0, "`test`")) { do_print=1; } 
        else { do_print=0; } } \
    { if (do_print) { print; } }' all_dbs.sql \
  | mysql -uuser -ppass

You might also like to consider using mydumper, which outputs individual files for all tables, so it's easy to restore the ones you want. See also nicer documentation: http://centminmod.com/mydumper.html

Upvotes: 1

Related Questions