首页 > 代码库 > mysql 事件

mysql 事件

SHOW VARIABLES LIKE ‘event_scheduler‘;#查看定时器是否开启

SET GLOBAL event_scheduler = 1; # 开启定时器

DROP EVENT
IF EXISTS activity_time_update;

CREATE EVENT activity_time_update ON SCHEDULE EVERY 1 DAY STARTS date_add(
date(curdate() + 1),
INTERVAL 5 SECOND
) ON COMPLETION PRESERVE DO
UPDATE `hnl_user_groups`
LEFT JOIN hnl_goods ON hnl_user_groups.good_id = hnl_goods.id
LEFT JOIN hnl_activity ON hnl_goods.activity_id = hnl_activity.id
SET hnl_user_groups.`status` = 3
WHERE
hnl_activity.endtime < NOW();

mysql 事件