Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #! /bin/bash
  2. ############################################
  3. # don't forget to chmod +x reset_database #
  4. # usage: ./reset_database dbname #
  5. # enter db password when prompted #
  6. ############################################
  7.  
  8. # set the database name
  9. DATABASE_NAME=$1
  10.  
  11. # get the db user from the keyboard
  12. read -p "DB User: " DBUSER
  13.  
  14. #get the db password from the keyboard
  15. read -s -p "DB Password: " DBPASSWORD
  16. # just to move to the next line
  17. echo ""
  18. # truncate all the tables in one go
  19. mysql -Nse 'show tables' -D $DATABASE_NAME -u$DBUSER -p$DBPASSWORD | while read table; do echo "SET FOREIGN_KEY_CHECKS = 0;truncate table \`$table\`;SET FOREIGN_KEY_CHECKS = 1;"; done | mysql $DATABASE_NAME -u$DBUSER -p$DBPASSWORD
  20. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement