Skip to content

Instantly share code, notes, and snippets.

@Jaesin
Created April 30, 2015 02:25
Show Gist options
  • Save Jaesin/c78d5a196f095db3df78 to your computer and use it in GitHub Desktop.
Save Jaesin/c78d5a196f095db3df78 to your computer and use it in GitHub Desktop.
Drop all tables.
# Drop all tables in a db.
function mysql-drop-tables {
if [[ $1 != "" ]]; then
if [[ $(get_yes "$@") != "1" ]]; then
echo "You are about to drop all files in the $1 database. Are you sure? (Y or N):"
read RESPONSE
fi
if [[ $(get_yes "$@") == "1" || $RESPONSE == "y" || $RESPONSE == "Y" ]]; then
mysqldump -uroot --add-drop-table --no-data $1 | grep ^DROP | mysql -uroot $1
echo "$1 has been emptied!"
else
echo "Operation canceled!"
fi
else
echo "Please specify a database."
fi
}
# Utility: checks for a -y flag as an attribute.
function get_yes {
setopt -s nocasematch
for i in "$@"; do
if [[ $i == "-y" ]]; then
echo 1
break
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment