如何自动删除每x分钟? [英] How to automatically delete every x minutes?
问题描述
我使用codeigniter框架
例如,我有表A.我希望我的系统每2分钟自动删除表A中的所有记录
是否可以完成?
谢谢
您可以使用MySQL事件计划程序。
先决条件: / p>
您必须在您的mysql服务器中启用event_scheduler ON。
检查事件调度程序是否 ON
或 OFF
SELECT @@ event_scheduler;
要启动event_scheduler ON
,请运行以下查询:
SET GLOBAL event_scheduler = ON;
$ b b
注意:如果您重新启动 MYSQL Server
,则事件计划程序状态将被重置,除非在配置文件中写入以下内容。在 my.ini 文件中,<>> 在 [mysqld]
[mysqld]
my.cnf 档案中的
event_scheduler = on
:
[mysqld]
event_scheduler = on
事件:
以下事件将从名为
tablename
。CREATE
EVENT`deleteEvent`
ON计划每两分钟起始时间2016-03-23 00:00:00'
完成不保存
ENABLE
DO
从tablename删除;
活动将首次开始
'2016-03-23 00:00:00'
之后,活动将每隔2分钟安排一次,并从表中删除数据。
您可以使用
Truncate
,而不是DELETE
。
I using codeigniter framework
For example, I have table A. I want my system automatically delete all records in table A every 2 minutes
Whether it can be done?
Thank you
解决方案You can use MySQL event Scheduler.
Prerequisite:
You have to have event_scheduler ON in your mysql server.
Check whether event scheduler is
ON
orOFF
SELECT @@event_scheduler;
To turn event_scheduler
ON
run the following query:
SET GLOBAL event_scheduler = ON;
Note: If you restart
MYSQL Server
then event scheduler status will be reset unless the following is written in the configuration file.For Windows: in my.ini file write this under
[mysqld]
section[mysqld] event_scheduler=on
For Linux: in my.cnf file
[mysqld] event_scheduler=on
Event:
The following event will delete data from table named
tablename
.CREATE EVENT `deleteEvent` ON SCHEDULE EVERY 2 MINUTE STARTS '2016-03-23 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM tablename;
The event will be started for the first time at
'2016-03-23 00:00:00'
and after that the event will be scheduled in every 2 minutes interval and will delete data from your table.You can use
Truncate
instead ofDELETE
.这篇关于如何自动删除每x分钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!