Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- MUSER="$1"
- MPASS="$2"
- MDB="$3"
- if [ $# -ne 3 ]; then
- echo "Usage: $0 {MySQL-User} {MySQL-Pass} {MySQL-DBName}"
- echo "Drops all tables/views from a MySQL"
- exit 1
- fi
- FINDOPT="-B --disable-column-names"
- COMMAND="mysql -u $MUSER -p$MPASS $MDB"
- VIEWOPT="show full tables where table_type=\"view\""
- TABSOPT="show full tables where table_type=\"base table\""
- TABLES=`$COMMAND $FINDOPT -e "$TABSOPT" | sed 's/BASE TABLE//g'`
- for t in $TABLES; do
- echo "Deleting table $t from $MDB database..."
- $COMMAND -e "drop table $t"
- done
- VIEWS=`$COMMAND $FINDOPT -e "$VIEWOPT" | sed 's/VIEW//g'`
- for v in $VIEWS; do
- echo "Deleting view $v from $MDB database..."
- $COMMAND -e "drop view $v"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement