MySQL

Enable the MySQL Event Scheduler

  • Log in to your MySQL database as root (if necessary, connect to the server first)
    • ssh user@host
  • Verify if event_scheduler is enabled by connecting to mysql server and executing SHOW PROCESSLIST command.
    • mysql -h localhost -u root -p
    • SHOW PROCESSLIST;
  • If the event scheduler is not enabled, add event_scheduler = ON to MySQL configuration file, at the [mysqld] section
    • sudo vi /etc/mysql/my.cnf
  •  Restart the MySQL server, for the changes to take effect
    • sudo /etc/init.d/mysql stop
    • sudo /etc/init.d/mysql start
  • event_scheduler should now be enabled, check through SHOW PROCESSLIST command, again
    • mysql> SHOW PROCESSLIST;
      +—-+—————–+———–+——+———+——+————————+——————+
      | Id | User | Host | db | Command | Time | State | Info |
      +—-+—————–+———–+——+———+——+————————+——————+
      | 1 | event_scheduler | localhost | NULL | Daemon | 18 | Waiting on empty queue | NULL |
      | 38 | root | localhost | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
      +—-+—————–+———–+——+———+——+————————+——————+
      2 rows in set (0.00 sec)

 

Creating an Event

https://dev.mysql.com/doc/refman/5.7/en/create-event.html

Example:

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

 

By horaz

Hello, my name is Horacio Conde, Vic’s proud father, an apprentice maker and a computer science engineer. I live in Mexico City and I’ve been working professionally in software development for more than fifteen years now. I’m very interested in technologies such as programming, The Internet of Things (IoT) (Arduino, Raspberry Pi), electronics, physical computing, automation, woodworking.

Leave a Reply

Your email address will not be published. Required fields are marked *