I am looking for a way to automatically clean table in MySQL once per day. Is this possible without using cron? The best solution would be a trigger, but any solution is applicable.
Asked
Active
Viewed 1.1k times
8
-
1Triggers should be avoided when possible. They typically create more issues when it comes to maintenance. – Kermit Feb 22 '14 at 15:35
1 Answers
18
One option is MySQL's EVENT
scheduler:
CREATE EVENT e_daily
ON SCHEDULE
EVERY 1 DAY
STARTS '2014-02-23 05:00:00' -- Time to start
COMMENT 'Descriptive comment'
DO
TRUNCATE yourtable;

Kermit
- 33,827
- 13
- 85
- 121
-
3Don't forget to 'set global event_scheduler=on', which is off by default. – Sunry Jul 19 '15 at 08:28