Drop all databases matching prefix

Shell script to drop all MySQL databases with the prefix ‘rupture’:

mysql -u user_name -e 'show databases' |
grep '^rupture' |
xargs -I "@@" echo mysql -u user_name -e '"DROP DATABASE @@"' > temp

chmod +x temp
./temp


Leave a Reply