Skip to content

Instantly share code, notes, and snippets.

@alexzhan
Last active December 26, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexzhan/7194658 to your computer and use it in GitHub Desktop.
Save alexzhan/7194658 to your computer and use it in GitHub Desktop.
drop many databases prefixed with 'test_'
#!/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