Solved

Pruning MySQL tables

Posted on 2014-04-21
5
587 Views
Last Modified: 2014-04-22
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
Comment
Question by:centem
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 40013649
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
 

Author Comment

by:centem
ID: 40013687
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
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 40014014
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
 

Author Comment

by:centem
ID: 40014427
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
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 40014479
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now