Mysql Event Not Working

前端 未结 9 1790
-上瘾入骨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 11:07

    For those wondering how to enable it by default at startup, add the following to your config file (my.ini, my.cnf):

    #Event scheduler can be set to 1 (On), 0 (Off), or Disabled
    event_scheduler=1
    

    Restart of the service is required in this case, so if you want minimal disruption, add this to the config file, and then run the SQL:

    SET GLOBAL event_scheduler = ON;
    

    That way, it will run for the current process, and if the server is restarted it will still work.

    Note that this doesn't work if the event_scheduler was set to disabled. In that case the only option is to restart the service.

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

    If you want your event_scheduler to startup automatically every time mysql server restarts, anywhere under the [mysqld] section of the my.ini or my.cnf file that you find in /etc/mysql you should place

    [mysqld]
    
    # turning on event_scheduler  
    event_scheduler=ON
    

    restart mysql to check if it is running (in command line terminal!)

    sudo service mysql restart
    

    then check your processlist

    SHOW PROCESSLIST
    

    you can check if your events are running by checking the last time they ran

    SELECT * FROM INFORMATION_SCHEMA.events
    
    0 讨论(0)
  • 2021-01-30 11:12

    I would just like to add to this thread. I dumped my database to another server and as a result the definer of my event had no such grant defined for the user. I updated my definer with

    ALTER DEFINER='root'@'localhost' EVENT event.name COMMENT '';
    

    Make sure your definer has the correct PRIVILEGES.

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