in reply to Deleting Old MySql Records With PERL
DELETE FROM table WHERE DATE (NOW (), date) >30
That's a terrible approach; it evaluates the expression for each record.
DELETE FROM table WHERE DATE < DATE_SUB(NOW(), INTERVAL 30 DAY)
That is the correct approach. Evaluate the expression just once, and do a simple comparison.
Run the statement from the console to determine if it is working. If it is not, break it apart and figure out why. Obviously, "DATE_SUB(NOW(), INTERVAL 30 DAY)" should be checked to work. Look at the documentation if you do not understand DATE_SUB()
After you are clear that it should work, try it within your script, where the issues would mainly be connectivity or rights related, having already solved any syntactical or type issues.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Deleting Old MySql Records With PERL
by Milti (Beadle) on Jul 15, 2016 at 16:55 UTC |