0

I'm using MySQL from localhost and I have the following MySQL event:

DELIMITER $$
ALTER DEFINER=`root`@`localhost` EVENT `UpdateEstatusCorreo` 
ON SCHEDULE EVERY 1 MINUTE STARTS '2016-10-05 07:30:00' 
ON COMPLETION NOT PRESERVE ENABLE COMMENT 'Actualizar status a 0 (false) para enviar el correo nuevamente' 
DO UPDATE email SET Enviado = 0$
DELIMITER ;

Ok, I know that MySQL event it's supposed to start on october 5th but I change my PC datetime, I execute MySQL query select now() and I get the expectated date (2016-10-05 07:29:00) but I refresh my table after 07:30 and nothing happen, I turn on mysql events with:

SET GLOBAL event_scheduler = ON;

And with SHOW PROCESSLIST this is what I get:

Processlist

What I'm doing wrong? How can I solve it?

  • your delimiter is $$ not $ . Also please check out my answer here: http://stackoverflow.com/a/37901661 . I would also recommend a begin and end block and a semi-colon after your update stmt – Drew Oct 03 '16 at 04:13
  • 1
    also set your system date back to the correct datetime. And have your event fire off 10-01 not that forward thing or messing with clocks – Drew Oct 03 '16 at 04:14
  • @Drew I create the event in phpmyadmin so I can't control my $$ and ; that query if from SQLyog, however the event finally work I don't know why or how –  Oct 03 '16 at 04:33
  • perhaps my [evt mgt](http://stackoverflow.com/a/38022108) answer could benefit you ( I say that knowing it would ). It is a good sonar for knowing what is going on with your events. Even if to just know they fired. – Drew Oct 03 '16 at 04:53

1 Answers1

0

The event scheduler doesn't sit and watch the system clock. It checks to see how long it needs to wait before an event needs to fire... and it waits. Testing this way, by changing the system time, is not valid unless you stop and start the MySQL Server daemon (or service) -- but do not do that. MySQL expects the system clock to be stable and you can destabilize things a bit by tweaking it like that. It's really best avoided... but also unnecessary.

STARTS can be set in the past, and will still fire EVERY 1 MINUTE from whatever arbitrary time in the past you select. If STARTS has seconds of :00 it will run the very next minute from when you create the event, when the clock hits :00. And every minute after that.

Running events show their own separate thread in the processlist (add a brief sleep, something like DO SLEEP(5); inside your event body if you want to catch it running... but note this makes the statement "complex," so you'd need BEGIN/END surrounding the event body) and they log their errors in the standard MySQL Server error log.

The stray $ at the end of the event also looks like an error, but the error log should reveal this if it is, and the event is created in spite of it.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427