Skip to content

Instantly share code, notes, and snippets.

@vijinho
Created August 21, 2015 18:14
Show Gist options
  • Save vijinho/a52489e005f2d81dc841 to your computer and use it in GitHub Desktop.
Save vijinho/a52489e005f2d81dc841 to your computer and use it in GitHub Desktop.
drop empty tables
#!/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