The EVENTS table provides information
about Event Manager events, which are discussed in
Section 27.5, “Using the Event Scheduler”.
The EVENTS table has these columns:
EVENT_CATALOGThe name of the catalog to which the event belongs. This value is always
def.EVENT_SCHEMAThe name of the schema (database) to which the event belongs.
EVENT_NAMEThe name of the event.
DEFINERThe account named in the
DEFINERclause (often the user who created the event), in'format.user_name'@'host_name'TIME_ZONEThe event time zone, which is the time zone used for scheduling the event and that is in effect within the event as it executes. The default value is
SYSTEM.EVENT_BODYThe language used for the statements in the event's
DOclause. The value is alwaysSQL.EVENT_DEFINITIONThe text of the SQL statement making up the event's
DOclause; in other words, the statement executed by this event.EVENT_TYPEThe event repetition type, either
ONE TIME(transient) orRECURRING(repeating).EXECUTE_ATFor a one-time event, this is the
DATETIMEvalue specified in theATclause of theCREATE EVENTstatement used to create the event, or of the lastALTER EVENTstatement that modified the event. The value shown in this column reflects the addition or subtraction of anyINTERVALvalue included in the event'sATclause. For example, if an event is created usingON SCHEDULE AT CURRENT_TIMESTAMP + '1:6' DAY_HOUR, and the event was created at 2018-02-09 14:05:30, the value shown in this column would be'2018-02-10 20:05:30'. If the event's timing is determined by anEVERYclause instead of anATclause (that is, if the event is recurring), the value of this column isNULL.INTERVAL_VALUEFor a recurring event, the number of intervals to wait between event executions. For a transient event, the value is always
NULL.INTERVAL_FIELDThe time units used for the interval which a recurring event waits before repeating. For a transient event, the value is always
NULL.SQL_MODEThe SQL mode in effect when the event was created or altered, and under which the event executes. For the permitted values, see Section 7.1.11, “Server SQL Modes”.
STARTSThe start date and time for a recurring event. This is displayed as a
DATETIMEvalue, and isNULLif no start date and time are defined for the event. For a transient event, this column is alwaysNULL. For a recurring event whose definition includes aSTARTSclause, this column contains the correspondingDATETIMEvalue. As with theEXECUTE_ATcolumn, this value resolves any expressions used. If there is noSTARTSclause affecting the timing of the event, this column isNULLENDSFor a recurring event whose definition includes a
ENDSclause, this column contains the correspondingDATETIMEvalue. As with theEXECUTE_ATcolumn, this value resolves any expressions used. If there is noENDSclause affecting the timing of the event, this column isNULL.STATUSThe event status. One of
ENABLED,DISABLED, orREPLICA_SIDE_DISABLED(prior to MySQL 8.2.0, this wasSLAVESIDE_DISABLED, now deprecated).REPLICA_SIDE_DISABLEDindicates that the creation of the event occurred on another MySQL server acting as a replication source and replicated to the current MySQL server which is acting as a replica, but the event is not presently being executed on the replica. For more information, see Section 19.5.1.16, “Replication of Invoked Features”. information.ON_COMPLETIONOne of the two values
PRESERVEorNOT PRESERVE.CREATEDThe date and time when the event was created. This is a
TIMESTAMPvalue.LAST_ALTEREDThe date and time when the event was last modified. This is a
TIMESTAMPvalue. If the event has not been modified since its creation, this value is the same as theCREATEDvalue.LAST_EXECUTEDThe date and time when the event last executed. This is a
DATETIMEvalue. If the event has never executed, this column isNULL.LAST_EXECUTEDindicates when the event started. As a result, theENDScolumn is never less thanLAST_EXECUTED.EVENT_COMMENTThe text of the comment, if the event has one. If not, this value is empty.
ORIGINATORThe server ID of the MySQL server on which the event was created; used in replication. This value may be updated by
ALTER EVENTto the server ID of the server on which that statement occurs, if executed on a replication source. The default value is 0.CHARACTER_SET_CLIENTThe session value of the
character_set_clientsystem variable when the event was created.COLLATION_CONNECTIONThe session value of the
collation_connectionsystem variable when the event was created.DATABASE_COLLATIONThe collation of the database with which the event is associated.
Notes
EVENTSis a nonstandardINFORMATION_SCHEMAtable.Times in the
EVENTStable are displayed using the event time zone, the current session time zone, or UTC, as described in Section 27.5.4, “Event Metadata”.For more information about
REPLICA_SIDE_DISABLEDand theORIGINATORcolumn, see Section 19.5.1.16, “Replication of Invoked Features”.
Example
Suppose that the user 'jon'@'ghidora' creates
an event named e_daily, and then modifies it a
few minutes later using an ALTER
EVENT statement, as shown here:
Press CTRL+C to copyDELIMITER | CREATE EVENT e_daily ON SCHEDULE EVERY 1 DAY COMMENT 'Saves total number of sessions then clears the table each day' DO BEGIN INSERT INTO site_activity.totals (time, total) SELECT CURRENT_TIMESTAMP, COUNT(*) FROM site_activity.sessions; DELETE FROM site_activity.sessions; END | DELIMITER ; ALTER EVENT e_daily ENABLE;
(Note that comments can span multiple lines.)
This user can then run the following
SELECT statement, and obtain the
output shown:
Press CTRL+C to copymysql> SELECT * FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME = 'e_daily' AND EVENT_SCHEMA = 'myschema'\G *************************** 1. row *************************** EVENT_CATALOG: def EVENT_SCHEMA: myschema EVENT_NAME: e_daily DEFINER: jon@ghidora TIME_ZONE: SYSTEM EVENT_BODY: SQL EVENT_DEFINITION: BEGIN INSERT INTO site_activity.totals (time, total) SELECT CURRENT_TIMESTAMP, COUNT(*) FROM site_activity.sessions; DELETE FROM site_activity.sessions; END EVENT_TYPE: RECURRING EXECUTE_AT: NULL INTERVAL_VALUE: 1 INTERVAL_FIELD: DAY SQL_MODE: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES, NO_ZERO_IN_DATE,NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION STARTS: 2018-08-08 11:06:34 ENDS: NULL STATUS: ENABLED ON_COMPLETION: NOT PRESERVE CREATED: 2018-08-08 11:06:34 LAST_ALTERED: 2018-08-08 11:06:34 LAST_EXECUTED: 2018-08-08 16:06:34 EVENT_COMMENT: Saves total number of sessions then clears the table each day ORIGINATOR: 1 CHARACTER_SET_CLIENT: utf8mb4 COLLATION_CONNECTION: utf8mb4_0900_ai_ci DATABASE_COLLATION: utf8mb4_0900_ai_ci
Event information is also available from the
SHOW EVENTS statement. See
Section 15.7.7.20, “SHOW EVENTS Statement”. The following statements are
equivalent:
Press CTRL+C to copySELECT EVENT_SCHEMA, EVENT_NAME, DEFINER, TIME_ZONE, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STARTS, ENDS, STATUS, ORIGINATOR, CHARACTER_SET_CLIENT, COLLATION_CONNECTION, DATABASE_COLLATION FROM INFORMATION_SCHEMA.EVENTS WHERE table_schema = 'db_name' [AND column_name LIKE 'wild'] SHOW EVENTS [FROM db_name] [LIKE 'wild']