Mysql Event Not Working

前端 未结 9 1788
-上瘾入骨i
-上瘾入骨i 2021-01-30 10:46

I have added the following simple test event on my mysql database via phpmyadmin:

CREATE DEFINER=`root`@`localhost` EVENT `my_event` 
ON SCHEDULE EVERY 1 MINUTE          


        
相关标签:
9条回答
  • 2021-01-30 10:53

    Verify if the event_scheduler is On - execute the following command:

    SHOW PROCESSLIST;
    

    It'll output a table/entries, you must look for an entry with User event_scheduler, and Command Daemon:

    Id           User         Host      db  Command Time    State            Info
    22870   event_scheduler localhost   \N   Daemon  23    Waiting for next activation  \N
    

    OR, you can also verify using the following command:

    SELECT @@global.event_scheduler;
    

    The result should be ON, otherwise set it off (will get 0 for the command), as stated in the next section.


    If you don't have any such entry (as above), you may start the event scheduler using the following command:

     SET GLOBAL event_scheduler = ON;
    

    Once done, you can verify if it has been executed properly using the SHOW PROCESSLIST command, as mentioned above.

    0 讨论(0)
  • 2021-01-30 10:55

    Temporal

    SET GLOBAL event_scheduler = ON;
    

    Will not work if event_scheduler is explicitly DISABLED, see the method below

    Permanent (needs restart)

    In your config file (In Ubuntu it's /etc/mysql/mysql.cnf):

    [mysqld]
    event_scheduler = ON
    

    Notes:

    The event_scheduler variable can have this possible states:

    • OFF (or 0) (default)
    • ON (or 1)
    • DISABLED: you cannot use the temporal enabling, you can only change state through the config file and restarting the server

    WARNING: Keywords ON / OFF are preferred over their numerical equivalents. And in fact Mysql Workbench doesn't recognize the configuration event_scheduler=1, it shows as OFF in the Options File section. Tested in Ubuntu with Mysql Workbench 8.0.17 and Mysql Server 5.7.27

    Although ON and OFF have numeric equivalents, the value displayed for event_scheduler by SELECT or SHOW VARIABLES is always one of OFF, ON, or DISABLED. DISABLED has no numeric equivalent. For this reason, ON and OFF are usually preferred over 1 and 0 when setting this variable.

    Source: https://dev.mysql.com/doc/refman/5.7/en/events-configuration.html

    0 讨论(0)
  • 2021-01-30 10:55

    Try

    SET GLOBAL event_scheduler = ON;
    DELIMITER $$
    CREATE DEFINER=`root`@`db01` EVENT `PRICEALERT_STATUS` 
    ON SCHEDULE EVERY 1 DAY STARTS TIMESTAMP(CURRENT_DATE) 
    DO BEGIN
    // Your Query
    END $$
    DELIMITER ;
    
    0 讨论(0)
  • 2021-01-30 10:58

    I just figured out that on MariaDB, after adding an event (in my case, it was the first one), you have to restart the event-scheduler

     SET GLOBAL event_scheduler = OFF;
    

    and then

     SET GLOBAL event_scheduler = ON;
    

    to make it actually bring the scheduler into "waiting for activation"-state.

    0 讨论(0)
  • 2021-01-30 11:00

    Remember to add in 'Commit', after 'DO BEGIN' or 'DO'. Works for me after that.

    0 讨论(0)
  • 2021-01-30 11:04

    Events are run by the scheduler, which is not started by default. Using SHOW PROCESSLIST is possible to check whether it is started. If not, run the command

     SET GLOBAL event_scheduler = ON;
    

    to run it.

    0 讨论(0)
提交回复
热议问题