Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Deleting Old MySql Records With PERLby chacham (Prior) |
on Jul 14, 2016 at 14:39 UTC ( [id://1167783]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Seekers of Perl Wisdom
|
|