Home > Net >  How to set up timing tasks in Mysql
How to set up timing tasks in Mysql

Time:01-05

I have an application and I want to run the scheduled task separately. So, I need to refresh the DateTime time in Mysql every 1 hour, and then judge the TODO based on the time. I am not sure which package to use, is there a recommendation? If I don't rely on code to perform timing tasks, is it possible? Any help is greatly appreciated!

CodePudding user response:

Just create an event:

CREATE EVENT update_todos
    ON SCHEDULE EVERY '1' DAY
    STARTS CURRENT_TIMESTAMP
    ON COMPLETION PRESERVE ENABLE
    DO 
BEGIN
   -- your query here;
END;

Also, make sure that the event scheduler is turned on. The event_scheduler system variable can be set in a configuration file:

[mysql]
event_scheduler=ON

The event_scheduler system variable can also be set dynamically at runtime by executing SET GLOBAL:

SET GLOBAL event_scheduler=ON;

CodePudding user response:

Since you are using Mysql, you can create an enter image description here

There are two ways to implement MySQL timing tasks:

1.Use MySQL event timing tasks To use MySQL's event schedule, you first need to enable event_scheduler on the server before it can be processed.

2.Use Linux's timing task crontab

This article has detailed examples, you can read it, I hope these are helpful to you:

https://www.mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event/

  •  Tags:  
  • Related