MySQL events between 12 hours

0

I'm creating an event that was already created in Sybase, this is done so that it runs every hour but it does between 7 in the morning and 7 in the afternoon. Does anyone know if this option is available with MySQL? I've been watching but I do not see anything regarding this option.

Thanks in advance!

    
asked by Oscar Marés Barrera 22.10.2018 в 15:23
source

1 answer

0

MySQL has a Event Scheduler that would allow you to emulate what you describe. I do not know the granularity with which you can define events in Sybase, but as you go along tuning you could achieve more or less the same.

The creation of an event has the syntax:

CREATE EVENT myevent
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
DO
  UPDATE myschema.mytable SET mycol = mycol + 1;

Now, you want an event that happens every 10 minutes, but only between two specific hours. One way could be:

DELIMITER //

CREATE EVENT my_event ON SCHEDULE EVERY 10 MINUTE DO
IF CURRENT_TIME BETWEEN '07:00:00' AND '19:00:00' THEN
   UPDATE myschema.mytable SET mycol = mycol + 1;
END IF//

DELIMITER ;

You could also play with the START and ENDS clauses, but you should be testing, because the ENDS clause could be interpreted as having fulfilled that term the event stops running.

You have to check that the scheduler is enabled in your MySQL installation. If you put

 SET GLOBAL event_scheduler = ON;

will be enabled, but if the initial configuration is disabled, that setting will be lost when you restart the service. You have to make sure that event_scheduler=ON appears in your configuration file so that it is always enabled.

In services where you do not have access to the service configuration, like Amazon RDS, you have to play with the parameters of the instance, as described here .

    
answered by 22.10.2018 / 16:32
source