My Profile Photo

Personal Webpage of David Duggins


Well, I was born on a normal day in July, 1981 and have been creating chaos ever since. Born in North Carolina, but raised in the aftermath of the Soviet Union, Kazakhstan, I have been messing around with computers nearly my entire life. I wrote my first program in assembly when I was 11. In my early teens I ran a BBS connected to Fidonet and started building a website for my band. In 1999 I was introduced to Linux, and it was love at first compile. I started my career in IT in the early 2000's doing IT for a Car Dealership in Charlotte NC. I wrote my first major web app in Cold Fusion (an ecom app) at that time. In 2006 I left Charlotte and moved down to Columbia where starting working as a developer, freelancer and consultant. Currently I am working as a freelance developer and DevOps consultant!!


Drop that table like it was hot!!

\n Friday night I ran some code on the server and I had made a tiny but fatal error. I mixed up a pair of booleans and code that should have made one set of seven tables, made thoose seven table over 1000 times!! My mySql GUI tools were not upto the challenge. I found a nifty little bit of code on the internet Check out the original here that drops all the tables in database. Drops ‘em like they were hot!!

mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" |
gawk '{print "drop table " $1 ","}' | mysql -u uname dbname

You could even do this from the iPhone!! Here is a breakdown for anyone that is a bit rusty on bash:

mysql -u uname dbname -e "show tables"

This (where uname is your username and dbname is your database name) run by itself will show you all the tables in the database. You have to add the option –password=password if the mysql is protected.

You then pipe it twice through grep -v (this show all BUT what you specify in grep. And here comes the great part….

gawk '{print "drop table " $1 ","}' | mysql -u uname dbname

You use gawk to print out “drop table” and pipe that through mysql again (just repeat minus the -e “show tables”)

And viola! problem solved!!

David

© 2024 David Duggins. All rights reserved.