The Event Scheduler (http://dev.mysql.com/doc/refman/5.1/en/events.html), another new feature of MySQL 5.1, permits the creation of tasks that will run automatically according to a schedule. The schedule is quite flexible and permits, for example, a statement to be run every ten seconds, starting from midnight of May 18, 2011. These can be one-time events or recurring ones.
We should first verify whether the scheduler is active on our server. If not, we need to activate it. Otherwise, nothing will happen! We will start by entering the following statement in the query box:
SHOW VARIABLES LIKE 'event%';
Next, we look in the results for a variable named event_scheduler
. If this variable is set to OFF
, we need to ask the system administrator (or someone with the SUPER
privilege) to execute the following statement:
SET GLOBAL event_scheduler = ON;
Every user who wants to create or drop an event needs the EVENT
privilege, either globally or on the database on which he or she plans to add the event. Please refer to Chapter 19 for details about granting such privileges.
The current phpMyAdmin version does not have an interface on which we could choose the various parts of the CREATE EVENT
statement. Therefore, the only method left is to use the SQL query box to enter the statement and to understand its syntax! Here, we will use a totally fictitious example:
CREATE EVENT add_page_count ON SCHEDULE EVERY 1 MINUTE DO UPDATE author set total_page_count = total_page_count + 1 WHERE id = 1;
You can now get some amusement by browsing the author
table once in a while, and see the counter incrementing for author 1.
Events are related to a single database, which is why you see an Events slider on the Structure page for the marc_book
database. Activating it reveals the following panel:
Indeed, this is a recurring event. We can use the first icon to edit the event (which will have the effect of deleting and recreating the event), and the second icon to remove it.
It's possible to generate event-related statements at the end of an SQL database export file by selecting the Add CREATE PROCEDURE / FUNCTION / EVENT option. Please remember that some events may have an expiration time. Hence, they may have vanished between the time you create them and the time you attempt to export them, unless the ON COMPLETION PRESERVE
clause was used when creating the event.
3.135.196.172