Solved

Pruning MySQL tables

Posted on 2014-04-21
5
635 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 35

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 35

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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 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