日期过期后自动删除表中的记录? [英] Auto delete a record in table when date is expired?
本文介绍了日期过期后自动删除表中的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在日期过期时自动删除记录,我正在创建机票预订网站.我需要从mysql数据库中删除所有过期的航班详细信息.我读过某个地方可以使用cron,但我不知道该怎么做.该脚本的任何帮助都将非常有帮助.
I would like to know how can I auto delete a record when date is expired, I'm creating a Air-ticket booking website. I need to delete from my mysql database all the expired flight details. I read somewhere that I can use cron but I have no idea how to do it. Any Help for the script will be very helpful.
推荐答案
You may try to use MySQL Events
for that:
CREATE EVENT IF NOT EXISTS `dbName`.`eventName`
ON SCHEDULE
EVERY 1 DAY // or 1 HOUR
COMMENT 'Description'
DO
BEGIN
DELETE FROM `dbName`.`TableName` WHERE `DateCol` < NOW();
END
注意,MySQL 事件计划程序需要要在您的服务器上启用:
NOTE that MySQL Event Scheduler need to be enabled on your server:
SET GLOBAL event_scheduler = ON;
更多信息此处.
这篇关于日期过期后自动删除表中的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文