Last active
December 26, 2015 18:29
-
-
Save alexzhan/7194658 to your computer and use it in GitHub Desktop.
drop many databases prefixed with 'test_'
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 | |
#originated from http://stackoverflow.com/questions/5457286/drop-multiple-databases | |
#firstly you should use mysql_config_editor to set up a "login path" which the mysql command line client can then use. | |
#http://architects.dzone.com/articles/passwordless-command-line | |
DB_STARTS_WITH="test_" | |
MYSQL="mysql" | |
DBS="$($MYSQL --login-path=restore -Bse 'show databases')" | |
for db in $DBS; do | |
if [[ "$db" == $DB_STARTS_WITH* ]]; then | |
echo "Deleting $db" | |
$MYSQL --login-path=restore -Bse "drop database $db" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment