drop all mysql databases

#!/bin/bash
# Remove all mysql databases

echo 'Enter MySQL user'
read MYSQL_USER

echo 'Enter MySQL password'
stty -echo
read MYSQL_PASSWD
stty echo

DATABASES=$( mysql -u $MYSQL_USER -p$MYSQL_PASSWD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database )

for i in ${DATABASES[*]}; do

  if [ $i != 'mysql' ] && [ $i != 'information_schema' ] && [ $i != 'performance_schema' ]; then

    echo $( date +%H:%M ) drop database: $i 
    time mysql -u $MYSQL_USER -p$MYSQL_PASSWD -e "DROP DATABASE $i"
  fi
done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s