mysqldatabaseeventsscheduled-tasksmysql-event

A MySQL Event should run once every month at the 1st day's 00:00:00 (Midnight)


I have Win XP os and XAMPP installed in my machine.

I need to run my event at 00:00:00(Midnight) of the 1st day of every month. Means 1st of every month. (e.g. jan 1st, Feb1 1st, March 1st, ... ).

And, I also need to call the stored procedure in the same event. And I want achieve all this using Event/Job only not from front end.

Please spend few minutes for my query.


Solution

  • The MySQL event syntax is very simple -

    DELIMITER $$
    CREATE EVENT event1
    ON SCHEDULE EVERY '1' MONTH
    STARTS '2011-05-01 00:00:00'
    DO 
    BEGIN
     -- your code
    END$$
    
    DELIMITER ;
    

    Event will start working on '2011-05-01' at '00:00:00' (datetime must be in a future).

    More information - Using the Event Scheduler

    Do not forget to enable global event scheduling thread -

    SET GLOBAL event_scheduler = 1;