Add 'drop.sh'
This commit is contained in:
parent
6bc0150047
commit
e30de5f0f5
1 changed files with 25 additions and 0 deletions
25
drop.sh
Normal file
25
drop.sh
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue