|
Saturday, 24 September 2011 14:47 |
|

In this short article I will describe how I went about deleting multiple database tables quickly without using the DROP DATABASE dbName statement. Feel free to skip right to the solution if you like. Background StoryAs part of changing one of our sites over to a new server I had to delete the existing Joomla database and import the sites actual database, which was exported as a mysql dump. Easy right? All you need to do is drop the database and create a new database. But I did not have permission to do this. In fact, I had very little knowledge of the environment and how it was initially set up, I was called to help get the site back online again. At this point it was obvious that I would need to use DROP TABLE tableName statements, but since joomla has quite a few tables and its extensions also have their own table. There were about 102 tables in total. Doing this manually seemed insane (we programmers do not like hard work :) ). So the first thought that jumped to mind was, I know, I will write a program to do this. But wait, what about input for that program? Well, there is a command to list all the tables in mysql SHOW TABLES which will list all the tables in the currently selected database. Great, so now all I have to do is to parse the data, maybe add it to a list, python's comma seperated list syntax should do. Finally, as I was manually going over the output I got from the show tables command, changing it to be an list in python, it hit me. Why do I need to do all this work to begin with? There is a much better way.
|
|
Last Updated on Sunday, 25 September 2011 15:32 |