Created
December 30, 2011 03:21
-
-
Save justinkelly/1537596 to your computer and use it in GitHub Desktop.
Simple MySQL - db refresh script - delete tables and import .sql
This file contains 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 | |
MUSER="MYSQL_USER" | |
MPASS="MYSQL_PASSWORD" | |
MDB="MYSQL_DB" | |
FILE="/path/to/sql/to/import.sql" | |
# Detect paths | |
MYSQL=$(which mysql) | |
AWK=$(which awk) | |
GREP=$(which grep) | |
TABLES=$($MYSQL -u $MUSER -p$MPASS $MDB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' ) | |
for t in $TABLES | |
do | |
echo "Deleting $t table from $MDB database..." | |
$MYSQL -u $MUSER -p$MPASS $MDB -e "drop table $t" | |
done | |
cat $FILE | mysql -u $MUSER -p$MPASS $MDB | |
echo "Sql imported" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment