Last active
August 29, 2015 14:00
-
-
Save kubaceg/11394877 to your computer and use it in GitHub Desktop.
Drop all tables from mysql database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Default settings | |
username="root" | |
dbname="db" | |
host="localhost" | |
while getopts ":u:d:h:" opt; do | |
case "$opt" in | |
u) username=$OPTARG;; | |
d) dbname=$OPTARG;; | |
h) host=$OPTARG;; | |
\?) echo "Invalid option: -$OPTARG" >&2 | |
exit 2;; | |
esac | |
done | |
echo "SET foreign_key_checks = 0;" > drop.sql | |
mysqldump -u $username -p --no-data $dbname -h $host | grep ^DROP >> drop.sql | |
echo "SET foreign_key_checks = 1;" >> drop.sql | |
mysql -u $username -p $dbname -h $host < drop.sql | |
rm drop.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Without additional parameters it will use default values