Guest User

Untitled

a guest
Jan 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #!/bin/bash
  2. MUSER="$1"
  3. MPASS="$2"
  4. MDB="$3"
  5. HOST="$4"
  6.  
  7. # Detect paths
  8. MYSQL=$(which mysql)
  9. AWK=$(which awk)
  10. GREP=$(which grep)
  11.  
  12. if [ $# -ne 4 ]
  13. then
  14. echo "With great power comes great responsibility"
  15. echo "Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name} {MySQL-Database-Host}"
  16. echo "Drops all tables"
  17. exit 1
  18. fi
  19.  
  20. TABLES=$($MYSQL -u $MUSER -p$MPASS -h $HOST $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 -u $MUSER -p$MPASS $MDB -e "drop table $t"
  26. done
Add Comment
Please, Sign In to add comment