Last active
October 26, 2017 18:51
-
-
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.
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
SET foreign_key_checks = 0; |
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
SET foreign_key_checks = 1; |
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/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