Script To Backup & Restore Each MySQL Database In Separate Files

Ref: http://stackoverflow.com/questions/9497869/export-and-import-all-mysql-databases-at-one-time

Here I want to backup all my database (more than 100 databases) in separate files. I can backup all the database in one single file like this:

But I want to pick only some of the databases to be imported on the different MySQL version and left out the rest (some of the databases I don’t want to be imported). From the top link, I create a new bash file ‘backup_each_db.sh’. Here is the code:

Make sure the ‘USER’ and ‘PASSWORD’ values for your MySQL server are correct!.
Then modify the file permission:

Then run the script:

SORRY, ONLY ADMIN CAN SHOW THIS!

To restore all the databases from the sql files, please run like this:
teddy@teddy:/media/teddy/Data/MASTER/MySQL/20180124_db_backup$ for SQL in *.sql; do DB=${SQL/\.sql/}; echo importing $DB; mysql -uroot -pYOURPASSWORD < $SQL; done
ref: https://stackoverflow.com/questions/4708013/import-multiple-sql-dump-files-into-mysql-database-from-shell
SORRY, ONLY ADMIN CAN SHOW THIS!

Leave a Reply

Your email address will not be published. Required fields are marked *