Skip to content

Instantly share code, notes, and snippets.

@mojoaxel
Last active October 26, 2017 18:51
Show Gist options
  • Save mojoaxel/1f0891fb0b9d5744aa3a to your computer and use it in GitHub Desktop.
Save mojoaxel/1f0891fb0b9d5744aa3a to your computer and use it in GitHub Desktop.
Import .sql files as tables to the database with the directoryname they are in.
SET foreign_key_checks = 0;
SET foreign_key_checks = 1;
#!/bin/sh
DB_SERVER="localhost"
DB_USER="xxxxxx"
DB_PASS="yyyyyy"
ROOT=`pwd`
for DIR in `find . -mindepth 1 -type d`; do
echo "Test"
echo "enterning $DIR ..."
DB=$(echo $DIR | cut -c 3-)
cd $DIR
for FILE in *.sql
do
echo ""
echo "$DIR/$FILE"
mysql -u $DB_USER -p$DB_PASS -h $DB_SERVER $DB < $ROOT/foreign_key_checks_OFF.sql
pv "$FILE" | mysql -u $DB_USER -p$DB_PASS -h $DB_SERVER $DB
mysql -u $DB_USER -p$DB_PASS -h $DB_SERVER $DB < $ROOT/foreign_key_checks_ON.sql
done
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment