Search code examples
mysqlmysql-event

Why does MySQL 5.7 Even Scheduler START datetime not match with the CREATE/ALTER EVENT START time?


After I create the event...

DELIMITER $$
CREATE DEFINER=`abc`@`localhost` EVENT `testEventYearly` ON SCHEDULE EVERY 1 YEAR STARTS '2018-01-01 00:00:00' ON COMPLETION PRESERVE ENABLE DO BEGIN
CALL `spTestEventYearly` ();
END$$

...I look in the mysql.event table and see a starts value of 2018-01-01 06:00:00. I've checked the date/time on the server and all is well. Why is there a difference in time? And will it execute at 06:00 or 00:00?


Solution

  • https://dev.mysql.com/doc/refman/5.7/en/create-event.html says:

    Times in the ON SCHEDULE clause are interpreted using the current session time_zone value. This becomes the event time zone; that is, the time zone that is used for event scheduling and is in effect within the event as it executes. These times are converted to UTC and stored along with the event time zone in the mysql.event table. This enables event execution to proceed as defined regardless of any subsequent changes to the server time zone or daylight saving time effects.

    (emphasis mine)

    I infer you are in the US Central time zone. You created the event when your local time zone was UTC -0600, and then the value stored in mysql.event was advanced six hours to UTC.