Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #!/bin/bash
  2. MHOST="$1"
  3. MUSER="$2"
  4. MPASS="$3"
  5. MDB="$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: ./mysqldroptables.sh {MySQL-Hostname} {MySQL-Username} {MySQL-Password} {MySQL-DBName}"
  15. echo "Drops all tables from a MySQL"
  16. exit 1
  17. fi
  18.  
  19. TABLES=$($MYSQL -h $MHOST -u $MUSER -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 -h $MHOST -u $MUSER -p$MPASS $MDB -e "drop table $t"
  25. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement