{"id":1034,"date":"2017-08-14T16:16:30","date_gmt":"2017-08-14T21:16:30","guid":{"rendered":"http:\/\/xfloyd.net\/blog\/?p=1034"},"modified":"2017-08-14T16:16:49","modified_gmt":"2017-08-14T21:16:49","slug":"event-scheduler-in-mysql","status":"publish","type":"post","link":"https:\/\/xfloyd.net\/blog\/?p=1034","title":{"rendered":"Event scheduler in MySql"},"content":{"rendered":"<p>Since Mysql version 5.1.6, the system supports the option to schedule the execution of some events, without need to use external software (cron, at, Task Scheduler, etc.) \u00a0or to change data as required for trigger implementation.<\/p>\n<p>To activate the schedule function in MySql, you have simply to execute in a client the following command:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-base\">SET GLOBAL event_scheduler = 1;<\/code><\/pre>\n<p>Then you can verify the correct system working, by executing the following command:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-base\">SHOW PROCESSLIST;<\/code><\/pre>\n<p style=\"text-align: center;\">\n<p>A task can be executed once or more times and can be defined via a SQL syntax.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-base\">CREATE EVENT DELETE_BASKET_DATA\r\n  ON SCHEDULE EVERY 1 MINUTE \r\n  DO DELETE FROM basket where created &gt; DATE_SUB(NOW(), INTERVAL 30 MINUTE);<\/code><\/pre>\n<p>When a task is executed, all data older than 30 minutes will be deleted.<\/p>\n<p>To show how many and which tasks have been defined on the database, you need to simply execute the command &#8220;SHOW EVENTS&#8221;.<\/p>\n<p style=\"text-align: center;\">\n<p>To erase a task, you can simply execute the following command<\/p>\n<pre class=\"line-numbers\"><code class=\"language-base\">DROP EVENT DELETE_BASKET_DATA;<\/code><\/pre>\n<p>By using this function, you can perform some maintenance tasks on data, without affecting other parts of your application. With such options, MySql was able to fill its gap with some of the most important relational databases currently available.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since Mysql version 5.1.6, the system supports the option to schedule the execution of some events, without need to use external software (cron, at, Task Scheduler, etc.) \u00a0or to change data as required for trigger implementation. To activate the schedule function in MySql, you have simply to execute in a client the following command: SET [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1034"}],"collection":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1034"}],"version-history":[{"count":2,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1034\/revisions"}],"predecessor-version":[{"id":1036,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1034\/revisions\/1036"}],"wp:attachment":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}