Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. MHOST="$1"
  4. MUSER="$2"
  5. MPASS="$3"
  6. MDB="$4"
  7.  
  8. # Detect paths
  9. MYSQL=$(which mysql)
  10. AWK=$(which awk)
  11. GREP=$(which grep)
  12.  
  13. if [ $# -ne 3 ]
  14. then
  15. echo "Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name}"
  16. echo "Drops all tables from a MySQL"
  17. exit 1
  18. fi
  19.  
  20. TABLES=$($MYSQL -h $MHOST -u $MUSER -p$MPASS $MDB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' )
  21.  
  22. for t in $TABLES
  23. do
  24. echo "Deleting $t table from $MDB database..."
  25. $MYSQL -h $MHOST -u $MUSER -p$MPASS $MDB -e "drop table $t"
  26. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement