Created
August 21, 2015 18:14
-
-
Save vijinho/a52489e005f2d81dc841 to your computer and use it in GitHub Desktop.
drop empty tables
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 | |
# path settings | |
MYSQL=`which mysql` | |
# mysql settings | |
DB="MYDB" | |
HOST="127.0.0.1" | |
USER="root" | |
PASS="root" | |
# backup file settings | |
OPTS="" | |
# get tables | |
for t in `$MYSQL --host=$HOST --user=$USER --password=$PASS $OPTS $DB -e'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_ROWS =0 AND TABLE_SCHEMA = "$DB"' | grep -v TABLE_NAME`; | |
do $MYSQL --host=$HOST --user=$USER --password=$PASS $OPTS $DB -e "DROP TABLE $t;"; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment