Home >Database >Mysql Tutorial >How to Schedule a Daily MySQL Event to Run at a Specific Time?
Scheduling MySQL Events at a Specific Time Each Day
In MySQL, the Event Scheduler allows you to automate tasks based on predefined schedules. However, the syntax you provided (CREATE EVENT...DO UPDATE...AT TIMESTAMP) is outdated.
Solution:
To create an event that updates a status field to "0" at 1 pm every day, follow these steps:
Revised Query:
CREATE EVENT event_name ON SCHEDULE EVERY 1 DAY STARTS (TIMESTAMP(CURRENT_DATE) + INTERVAL 1 DAY + INTERVAL 1 HOUR) DO UPDATE `ndic`.`students` SET `status` = '0';
Alternative to TIMESTAMP:
The STARTS statement uses TIMESTAMP(CURRENT_DATE) as the starting point for the schedule. However, you can also use the NOW() function, which returns the current time.
STARTS (NOW() + INTERVAL 1 DAY + INTERVAL 1 HOUR)
The above is the detailed content of How to Schedule a Daily MySQL Event to Run at a Specific Time?. For more information, please follow other related articles on the PHP Chinese website!