自动删除mysql tabel数据 [英] automatic delete of mysql tabel data

查看:78
本文介绍了自动删除mysql tabel数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi2all

i想要在5分钟之后自动删除mysql tabel数据怎么做?



http://pastebin.com/SksY4RZE [ ^ ]

hi2all
i want to automatic delete of mysql tabel data after 5 miuntue how to do that ?

http://pastebin.com/SksY4RZE[^]

推荐答案

嗯,棘手的部分是5分钟后的要求。您可以在服务器上安排任何命令 - 实际上这取决于您拥有的访问级别和/或您的托管合作伙伴提供的服务。如果没有,你可以使用穷人的老兄方法:你不会在5分钟后完全删除数据,但是在这个间隔到期后的第一个请求处理。



在两种情况下都有以下想法:

1)在表中添加一个时间戳,并将其设置为插入到当前时间戳值,让'' s称之为TS:

Well, the tricky part is the "after 5 minutes" requirement. Can you schedule any command on the server - actually this depends on the access level you have and/or the services your hosting partner provides. If not, you can use the "poor man''s crone" approach: you don''t delete the data exactly after that 5 minutes, but at the first request processing after the expiration of this interval.

The idea is the following in both cases:
1) add a timestamp to your table, and set it on insert to the current timestamp value, let''s call it TS:
CREATE TABLE myTable 
(
 TS TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
 //rest of the table declaration
);



插入,只需省略此字段。

2)处理任何请求时,或按计划运行时,只需运行以下命令:


On insert, just omit this field.
2) when processing any request / or at schedule, just run following command:

DELETE FROM myTable WHERE TIMESTAMPDIFF(MINUTE,TS,CURRENT_TIMESTAMP)>5 


这篇关于自动删除mysql tabel数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆