Reputation: 12299
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
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