Skip to content

Instantly share code, notes, and snippets.

@mindevolution
Last active March 16, 2021 02:33
Show Gist options
  • Save mindevolution/b560ed8e8085d242f5ad to your computer and use it in GitHub Desktop.
Save mindevolution/b560ed8e8085d242f5ad to your computer and use it in GitHub Desktop.
Mysql drop multiple database
#!/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