Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个系统,您可以在其中“免费”获得一些东西,但每 7 天只能获得一次,我目前在每 7 天一次的部分中遇到问题。
我想要做的是在一个或多个条目超过 7 天后删除某个表中的条目。相关表有一个 ID、USERNAME 和 DATE 列。
有什么想法吗?
它应该很简单:
delete from theTable where date < now() - interval 7 days;
确保足够频繁地运行它,这样您就不必删除很多行。 如果您处于没有复制的环境中,您可以继续添加限制
delete from theTable where date < now() - interval 7 days limit 1000;
如果这是一个大表,请在日期(或日期第一个)上放置一个索引,这样它就不会进行表扫描。