Skip to content

Instantly share code, notes, and snippets.

@alkavan
Last active December 21, 2015 06:19
Show Gist options
  • Save alkavan/6263441 to your computer and use it in GitHub Desktop.
Save alkavan/6263441 to your computer and use it in GitHub Desktop.
Script to import MySQL databases from dumps
#/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