Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #!/bin/bash
  2. MUSER="$1"
  3. MPASS="$2"
  4. MDB="$3"
  5.  
  6. if [ $# -ne 3 ]; then
  7. echo "Usage: $0 {MySQL-User} {MySQL-Pass} {MySQL-DBName}"
  8. echo "Drops all tables/views from a MySQL"
  9. exit 1
  10. fi
  11.  
  12. FINDOPT="-B --disable-column-names"
  13. COMMAND="mysql -u $MUSER -p$MPASS $MDB"
  14. VIEWOPT="show full tables where table_type=\"view\""
  15. TABSOPT="show full tables where table_type=\"base table\""
  16.  
  17. TABLES=`$COMMAND $FINDOPT -e "$TABSOPT" | sed 's/BASE TABLE//g'`
  18. for t in $TABLES; do
  19. echo "Deleting table $t from $MDB database..."
  20. $COMMAND -e "drop table $t"
  21. done
  22.  
  23. VIEWS=`$COMMAND $FINDOPT -e "$VIEWOPT" | sed 's/VIEW//g'`
  24. for v in $VIEWS; do
  25. echo "Deleting view $v from $MDB database..."
  26. $COMMAND -e "drop view $v"
  27. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement