Mysql:每 10 秒删除 5 年以上的所有行 [英] Mysql: Deleting all rows older than 5 year in every 10 seconds
本文介绍了Mysql:每 10 秒删除 5 年以上的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除 mysql 表(项目)中超过 5 年的行.
I want to delete the rows older than 5 year in mysql table(item).
item
----------------
id neme date_and_time
1 a 2015-04-11 11:10:04
2 b 2005-05-22 11:10:04
3 c 2007-06-21 11:10:04
我该如何做这个删除操作?
How can i doing this delete action?
我还想每 10 秒运行一次删除操作,我可以使用事件调度程序和触发器来执行此操作吗?这两个函数有什么不同?
Also I want to run this delete action in every 10 seconds, I can do this using event scheduler and trigger? What is the different for this two function?
推荐答案
尝试创建这样的事件:
CREATE EVENT DO_DELETE_OP
ON SCHEDULE
EVERY 10 SECOND
DO DELETE FROM item WHERE date_and_time < DATE_SUB(NOW(), INTERVAL 60 MONTH);
这篇关于Mysql:每 10 秒删除 5 年以上的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文