Last active
March 16, 2021 02:33
-
-
Save mindevolution/b560ed8e8085d242f5ad to your computer and use it in GitHub Desktop.
Mysql drop multiple 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 | |
MUSER='root' # db username | |
MPASS='root' # db password | |
# db array to be deleted | |
declare -a DROP_DBS=(knowpath mydb xhprof ) | |
# loop dbs and delete db | |
DBS=`(mysql -u$MUSER -p$MPASS -Bse 'SHOW DATABASES')` | |
for db in $DBS; do | |
for db_del in ${DROP_DBS[@]}; do | |
if [ "$db" = "$db_del" ]; then | |
echo "Deleting db $db_del" | |
mysql -u$MUSER -p$MPASS -Bse "DROP DATABASE $db_del" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment