25 lines
No EOL
518 B
Bash
25 lines
No EOL
518 B
Bash
#!/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 |