Last active
December 21, 2015 06:19
-
-
Save alkavan/6263441 to your computer and use it in GitHub Desktop.
Script to import MySQL databases from dumps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# Export databases first with the following command: | |
# mysqldump -u user -p db-name > db-name.dbd | |
# Configure your new database | |
file_ext=".dbd" | |
db_user="root" | |
db_pass="myrootpassword" | |
# Loop files and import them into local database | |
for f in *.db ; do | |
db=${f/$file_ext} | |
create_cmd="CREATE DATABASE IF NOT EXISTS ${db};" | |
echo -e "Creating database: ${db}" | |
mysql -u $db_user -p$db_pass -e "${create_cmd}" | |
echo -e "Importing database ${db} ... wait, it can take a while" | |
mysql -u $db_user -p$db_pass $db < $f | |
echo -e "Done importing ${f} into ${db}\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment