Home >Database >Mysql Tutorial >How to Schedule a Daily MySQL Event to Update a Database Field at 1 PM?

How to Schedule a Daily MySQL Event to Update a Database Field at 1 PM?

Susan Sarandon
Susan SarandonOriginal
2024-11-28 12:25:12943browse

How to Schedule a Daily MySQL Event to Update a Database Field at 1 PM?

MySQL Event Scheduling for Specific Daily Time

Question: How can I schedule an event to update a MySQL database field to "0" every day at 1 pm using the MySQL Event Scheduler?

Answer: To achieve this, you can utilize the MySQL Event Scheduler with the following query:

CREATE EVENT event_name
ON SCHEDULE
  EVERY 1 DAY
  STARTS CURRENT_TIMESTAMP + INTERVAL 13 HOUR
DO
  UPDATE `ndic`.`students`
  SET `status` = '0';

Explanation:

  • EVERY 1 DAY: Specifies that the event should execute every day.
  • STARTS CURRENT_TIMESTAMP INTERVAL 13 HOUR: Sets the event to start at 1 pm (13 hours after midnight) on the first day it is created.
  • interval: To indicate a time duration, you can use the INTERVAL keyword followed by the number of units and the unit type (e.g., HOUR or DAY).

Alternative to TIMESTAMP:

You can use CURRENT_DATE and CURRENT_TIME instead of TIMESTAMP to specify the date and time components separately. For example, to start the event at 1 pm on a specific date, you can use the following:

STARTS (CURRENT_DATE + INTERVAL 1 DAY + INTERVAL 13 HOUR)

The above is the detailed content of How to Schedule a Daily MySQL Event to Update a Database Field at 1 PM?. 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