• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 707
  • Last Modified:

Pruning MySQL tables

Greetings,
I've inherited a system that has run out of disk space in the /var/lib/mysql directory. I was instructed to prune a bunch of tables (about 50 or more tables). I am a newbie with MySQL and don't want to break the system.

By pruning do they mean to delete rows in each of the tables or to delete the set of tables. In either case, is there a MySQL command that can do it for all tables? All the table names that I have to prune start with the same unique  set of characters.
0
centem
Asked:
centem
  • 2
  • 2
1 Solution
 
Terry WoodsIT GuruCommented:
Most likely it would be to delete some (likely not all) rows in the tables.

However, instructions aren't always given in technical language so no matter what the "correct" definition is of the word "prune" you should still be clarifying the request with someone who knows what is meant. It is much better to briefly bother someone getting a clear requirement than it is to waste hours of peoples time recovering data that shouldn't have been deleted.

If you have a look at the data in the tables, you will likely get some idea of how appropriate it is to delete some of it. For example, if a history of user logins has been stored for the last 10 years, then deleting the last 5 years would probably be appropriate. There may be a reason to export the data to file (for writing to DVD or other archiving media) in case it's ever needed. Just ensure it's well labelled or it won't be useful if it is needed!
0
 
centemAuthor Commented:
TerryAtOpus,

I checked and it is to delete the rows. The tables are not required for the functionality of the app is supports. Also, I did a VM snapshot of the system in case I have to revert to it.
0
 
Dan CraciunIT ConsultantCommented:
DELETE FROM table_name
WHERE condition

If you remove the WHERE part it will delete all rows, same as
TRUNCATE TABLE table_name

The difference is that TRUNCATE resets the auto_increment counter to 0.

HTH,
Dan
0
 
centemAuthor Commented:
Thanks Dan. Is there a way to do this for more than one table at once. I have to do this for about 50 tables.
0
 
Dan CraciunIT ConsultantCommented:
Edit: Wrong window. Posted code from another question :)

On topic: You need to do them one at a time. I don't know a way to mass truncate tables.

But if you use PHPMyAdmin, Adminer, SQLYog, HeidiSQL or any MySQL manager you just click on the table, and then click on "Empty table" so 50 tables should not take more than 2 minutes.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now