diff --git a/drop.sh b/drop.sh new file mode 100644 index 0000000..44cfa66 --- /dev/null +++ b/drop.sh @@ -0,0 +1,25 @@ +#!/bin/bash +#drop tables in database mysql +USER="$1" +PASS="$2" +DB="$3" + +# Detect paths +MYSQL=$(which mysql) +AWK=$(which awk) +GREP=$(which grep) + +if [ $# -ne 3 ] +then + echo "Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name}" + echo "Drops all tables from a MySQL" + exit 1 +fi + +TABLES=$($MYSQL -u $USER -p$PASS $DB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' ) + +for t in $TABLES +do + echo "Deleting $t table from $DB database..." + $MYSQL -u $USER -p$PASS $DB -e "drop table $t" +done \ No newline at end of file