Skip to content

Restore of mysqldump taken with –all-databases

This gotcha always gets me and when I google it I get nowhere.

Backup all databases:
BACKUP_FILE=`/mnt/backups/all_databases_`date -I`-`echo $RANDOM % 1000 | bc`.sql`
mysqldump -u root -h --all-database > $BACKUP_FILE

Restore a specific database:
RESTORE_FILE=`ls -tr /mnt/backups/*.sql | tail -n 1`
mysql -u root -h
drop database db_name;
create database db_name;
mysql -u root -h db_name < $RESTORE_FILE

note: when restoring a database, you may need to use the same DB name as the original

Post a Comment

You must be logged in to post a comment.