Solved

MySQL auto purge

Posted on 2013-06-28
10
246 Views
Last Modified: 2014-02-03
I have a HMI that will be installed in remote field location, collecting data in MySQL tables over time.  What tools does MySQL offer where I can set up for certain tables to be purged periodically weather based on a time period or on space.
Since this machine will be stand-alone I'm just looking for a way for this MySQL to manage itself to an extent just so the hard drive doesn't fill up.  we shoulnd't need more than 3 months history on data at the most.
0
Comment
Question by:cqr213
10 Comments
 
LVL 23

Assisted Solution

by:nemws1
nemws1 earned 100 total points
ID: 39284953
Usually, I would do this with 'cron' and not with MySQL inself, although it does have an event scheduler, you have a lot more control with cron (or a scheduled task if you're using windows).

More info on MySQL's event scheduler:   http://dev.mysql.com/doc/refman/5.1/en/events.html
0
 

Author Comment

by:cqr213
ID: 39289865
Can you please elaborate?
So by default will tables in a MySQL schema just append to new data or does it just add until it fill up all space?
0
 
LVL 34

Assisted Solution

by:gr8gonzo
gr8gonzo earned 300 total points
ID: 39315628
I would use a scripting language to create queries to analyze and drop data. For example, in PHP:

<?php
mysql_connect("localhost","username","password");
mysql_select_db("database_name");

mysql_query("DELETE FROM yourtable WHERE someDateTimeField <= NOW() - INTERVAL 3 MONTH");
?>
0
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 300 total points
ID: 39315630
I would also try running a SELECT on that query first to make sure it's grabbing only the data you want to delete. Deletes are permanent!
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39315758
What's an HMI?
0
 

Author Comment

by:cqr213
ID: 39315806
Ok however I'm not familiar with PHP.  Is there a way for me to do this from inside Workbench?  I was hoping it was as easy as maybe doing a Scheduled task in windows or a event schedule in Workbench somehow..

HMI - Human Machine Interface
It's basically just a computer running software that controls mechanical devices via PLC's (I/O).
0
 
LVL 34

Assisted Solution

by:gr8gonzo
gr8gonzo earned 300 total points
ID: 39315869
Man, I was certain it stood for a Hibernating Mammoth Inebriator. Twenty bucks down the drain.

You can also just create a SQL file with the commands you want to run and use Windows task scheduler to run a command like:

C:\path\to\mysql.exe --user=YourUsernameHere --password=PasswordHere --database=YourDatabase < C:\path\to\the\file.sql
0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 100 total points
ID: 39317624
I'd partition the tables by date range and then have a cron job that kicks off a script that drops the older partition(s) and repartitions as needed.

Dropping partitions is more efficient than using select/delete queries.

RANGE Partitioning
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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

15 Experts available now in Live!

Get 1:1 Help Now