Saturday, November 17, 2007

Deleting data from all tables in MySQL

Why would I need it? Well, I am in the process of transitioning from Access to MySQL, thats why. The porting process is slow, and data keeps getting added to Access. So I figured out a way to clean old data from MySQL tables.
At the mysql prompt:
mysql> use dbName;
mysql> show tables;

**get a list of tables here**

Select the table names and paste it in your editor of choice. Add "delete from " to the beginning by running a regular expression search and replace operation for the special character ^. Thats it! You have a list of delete statements, which you can just copy paste at the MySQL prompt.

No comments: