We Recommend

bash Cookbook: Solutions and Examples for bash Users bash Cookbook: Solutions and Examples for bash Users
bash Cookbook teaches shell scripting the way Unix masters practice the craft. It presents a variety of recipes and tricks for all levels of shell programmers so that anyone can become a proficient user of the most common Unix shell -- the bash shell -- and cygwin or other popular Unix emulation packages.


Posted By

berkes on 02/04/08


Tagged

mysql administration awk


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

basicmagic


Remove all tables with a certain pattern from the database


Published in: Bash 


This script removes (DROPS) all tables that start with foo_. Usefull if you had some CMS or application that (ab)uses table prefixing, and want to clean 0ut your database.

NOTE: the data is remove FOREVER! So take good casre: make backups and all the likes. Try on a test-database first!

  1. mysql -u[username] -p[password] -h[host] [databasename] -e "show tables like 'foo_%';" -N | awk '{ print "DROP TABLE " $1 ";" };' | mysql -u[username] -p[password] -h[host] [databasename]

Report this snippet 

You need to login to post a comment.