Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- ############################################
- # don't forget to chmod +x reset_database #
- # usage: ./reset_database dbname #
- # enter db password when prompted #
- ############################################
- # set the database name
- DATABASE_NAME=$1
- # get the db user from the keyboard
- read -p "DB User: " DBUSER
- #get the db password from the keyboard
- read -s -p "DB Password: " DBPASSWORD
- # just to move to the next line
- echo ""
- # truncate all the tables in one go
- 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
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement