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
Release: 2024-12-05 05:45:10
Original
618 people have browsed it

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)
Copy after login
  • 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';
Copy after login
  • 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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template