[每天在特定时间自动触发Mysql查询

问题描述 投票:-1回答:2

我想每天在00:01 AM给我的用户奖励,所以我正在mysql中寻找一个自动触发器来更新用户的奖励。

UPDATE users SET bonus = bonus + 10

我该怎么做?谢谢

php mysql database-trigger
2个回答
0
投票

SET GLOBAL event_scheduler = ON;

示例:

CREATE EVENT test_event_02
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE
ON COMPLETION PRESERVE
DO
   INSERT INTO messages(message,created_at)
   VALUES('Test MySQL Event 2',NOW());

完整教程here

MySQL官方link


0
投票

您可以为此创建预定的事件:

create event grant_user_bonus_daily
on schedule every 1 day
starts current_date + interval 1 day + interval 1 minute -- starts tomorrow at 00:01
do
    update users set bonus = bonus + 10
end
© www.soinside.com 2019 - 2024. All rights reserved.