Guest User

Untitled

a guest
Apr 9th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #!/bin/bash
  2. MUSER="$1"
  3. MPASS="$2"
  4. MDB="$3"
  5. MHOST="$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 "Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name} {MySQL-Host}"
  15. echo "Drops all tables from a MySQL"
  16. exit 1
  17. fi
  18.  
  19. TABLES=$($MYSQL -u $MUSER -h $MHOST -p$MPASS $MDB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' )
  20.  
  21. for t in $TABLES
  22. do
  23. echo "Deleting $t table from $MDB database..."
  24. $MYSQL -u $MUSER -h $MHOST -p$MPASS $MDB -e "SET FOREIGN_KEY_CHECKS=0; drop table $t; SET FOREIGN_KEY_CHECKS=1;"
  25. done
Add Comment
Please, Sign In to add comment