Home >Database >Mysql Tutorial >How to Schedule Daily Tasks in MySQL Event Scheduler at a Specific Time?

How to Schedule Daily Tasks in MySQL Event Scheduler at a Specific Time?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-05 05:45:10632browse

How to Schedule Daily Tasks in MySQL Event Scheduler at a Specific Time?

MySQL Event Scheduler: Scheduling Tasks Daily at a Specific Time

Question: How can MySQL Event Scheduler be utilized to perform daily updates at a precise time?

Answer:

To schedule an event to execute every day at a specific time, such as 1 PM, follow these steps:

  • Define Event Name and Schedule: Begin by creating an event with a unique name. Utilize the ON SCHEDULE clause to specify the frequency and time for the task. For daily execution at 1 PM, use the following syntax:
CREATE EVENT event_name
ON SCHEDULE
EVERY 1 DAY
STARTS (TIMESTAMP(CURRENT_DATE) + INTERVAL 1 DAY + INTERVAL 1 HOUR)
  • Specify Triggering Action: Within the DO section, define the action to be performed at the scheduled time. In this case, you want to update the status column to '0' daily:
DO
UPDATE `ndic`.`students`
SET `status` = '0';
  • Additional Considerations:

    • For maximum accuracy, it is recommended to use TIMESTAMP as the scheduling mechanism, as it provides nanosecond precision.
    • Alternatively, you can specify a specific value using AT syntax, but it will execute only once at the specified time.

The above is the detailed content of How to Schedule Daily Tasks in MySQL Event Scheduler at a Specific Time?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn