nix, shell, perl, php, mysql and mac os x tips and tricks

Monday, June 15, 2009

Delete MYSQL tables that match a pattern. Run from the command line

Not terribly safe if you use the password on the cmd line.
mysql -u USER -pPASSWORD dbname -e "show tables" | grep "[0-9A-Z][0-9A-Z]_[0-9A-Z][0-9A-Z][0-9A-Z]_blah" | gawk '{print "drop table " $1 ";"}' | mysql -u USER -pPASSWORD dbname 

No comments:

Post a Comment