Home >Database >Mysql Tutorial >How Can I Schedule a MySQL Event to Run Daily at a Specific Time?
Imagine you have a database and need to update the status of records to "0" every day at 1 pm. Here's a query that might initially come to mind:
CREATE EVENT RESET ON SCHEDULE AT TIMESTAMP DO UPDATE `ndic`.`students` SET `status` = '0';
But that query uses TIMESTAMP, which doesn't allow for scheduling at a specific time. So, how can we achieve this result?
The answer lies in the STARTS keyword. Here's a modified query that executes the event every day at 1 pm:
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';
This query starts the event at (CURRENT_DATE 1 DAY 1 HOUR) and repeats it every 24 hours thereafter. This ensures that the event triggers at 1 pm every day, as desired.
The above is the detailed content of How Can I Schedule a MySQL Event to Run Daily at a Specific Time?. For more information, please follow other related articles on the PHP Chinese website!