Skip to content

Instantly share code, notes, and snippets.

@tobiase
Forked from vijinho/drop_tables.sh
Created October 21, 2015 22:08
Show Gist options
  • Save tobiase/0eb4147f9aab143dd856 to your computer and use it in GitHub Desktop.
Save tobiase/0eb4147f9aab143dd856 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