EVENTS 表提供有关事件管理器事件的信息,这些内容在 第 27.4 节,“使用事件调度器” 中进行了讨论。The EVENTS table provides information
about Event Manager events, which are discussed in
Section 27.4, “Using the Event Scheduler”.
EVENTS 表具有以下列:The EVENTS table has these columns:
EVENT_CATALOG事件所属目录的名称。该值始终为
def。The name of the catalog to which the event belongs. This value is alwaysdef.EVENT_SCHEMA事件所属模式(数据库)的名称。The name of the schema (database) to which the event belongs.
EVENT_NAME事件的名称。The name of the event.
DEFINERDEFINERDEFINER子句中指定的账户(通常是创建事件的用户),格式为'。The account named in theuser_name'@'host_name'DEFINERclause (often the user who created the event), in'format.user_name'@'host_name'TIME_ZONE事件的时区,用于安排事件的时间,并在事件执行期间生效。默认值为
SYSTEM。The 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 isSYSTEM.EVENT_BODY事件
DO子句中语句使用的语言。该值始终为SQL。The language used for the statements in the event'sDOclause. The value is alwaysSQL.EVENT_DEFINITION构成事件的
DO子句的 SQL 语句文本;换句话说,该事件执行的语句。The text of the SQL statement making up the event'sDOclause; in other words, the statement executed by this event.EVENT_TYPE事件重复类型,可以是
ONE TIME(一次性)或RECURRING(重复)。The event repetition type, eitherONE TIME(transient) orRECURRING(repeating).EXECUTE_AT对于一次性事件,这是在创建事件所使用的
CREATE EVENT语句的AT子句中指定的DATETIME值,或最近修改该事件的ALTER EVENT语句中的值。本列显示的值会反映事件AT子句中包含的任何INTERVAL值的加减。例如,如果事件使用ON SCHEDULE AT CURRENT_TIMESTAMP + '1:6' DAY_HOUR创建,并且事件创建时间为 2018-02-09 14:05:30,则本列显示的值为'2018-02-10 20:05:30'。如果事件的时间由EVERY子句而非AT子句确定(即事件是重复事件),则本列的值为NULL。For a one-time event, this is theDATETIMEvalue 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_VALUE对于重复事件,表示在事件执行之间需要等待的间隔数量。对于一次性事件,该值始终为
NULL。For a recurring event, the number of intervals to wait between event executions. For a transient event, the value is alwaysNULL.INTERVAL_FIELD重复事件在重复之前等待的时间单位。对于一次性事件,该值始终为
NULL。The time units used for the interval which a recurring event waits before repeating. For a transient event, the value is alwaysNULL.SQL_MODE事件创建或修改时生效的 SQL 模式,以及事件执行时所使用的模式。有关允许的值,请参见第 7.1.11 节,“服务器 SQL 模式”。The 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”.
STARTSSTARTS循环事件的开始日期和时间。该值显示为
DATETIME值,如果事件未定义开始日期和时间,则为NULL。对于瞬时事件,此列始终为NULL。对于定义中包含STARTS子句的循环事件,此列包含相应的DATETIME值。与EXECUTE_AT列一样,该值会解析所使用的任何表达式。如果没有影响事件时间的STARTS子句,此列为NULLThe start date and time for a recurring event. This is displayed as aDATETIMEvalue, 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 isNULLENDSENDS对于定义中包含
ENDS子句的重复事件,此列包含相应的DATETIME值。与EXECUTE_AT列一样,此值会解析所使用的任何表达式。如果没有ENDS子句影响事件的时间,则此列为NULL。For a recurring event whose definition includes aENDSclause, 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.STATUSSTATUS事件状态。取值为
ENABLED、DISABLED或REPLICA_SIDE_DISABLED(在 MySQL 8.2.0 之前,此值为SLAVESIDE_DISABLED,现已弃用)。REPLICA_SIDE_DISABLED表示该事件是在作为复制源的另一台 MySQL 服务器上创建并复制到当前作为副本的 MySQL 服务器的,但该事件目前未在副本上执行。有关更多信息,请参见 第 19.5.1.16 节,“调用功能的复制”。The event status. One ofENABLED,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_COMPLETION可取值为
PRESERVE或NOT PRESERVE其中之一。One of the two valuesPRESERVEorNOT PRESERVE.CREATED事件创建的日期和时间。这是一个
TIMESTAMP值。The date and time when the event was created. This is aTIMESTAMPvalue.LAST_ALTERED事件最后修改的日期和时间。这是一个
TIMESTAMP值。如果事件自创建以来未被修改,则此值与CREATED值相同。The date and time when the event was last modified. This is aTIMESTAMPvalue. If the event has not been modified since its creation, this value is the same as theCREATEDvalue.LAST_EXECUTED事件最后执行的日期和时间。这是一个
DATETIME值。如果事件从未执行过,则此列为NULL。The date and time when the event last executed. This is aDATETIMEvalue. If the event has never executed, this column isNULL.LAST_EXECUTED表示事件的开始时间。因此,ENDS列的值永远不会小于LAST_EXECUTED。LAST_EXECUTEDindicates when the event started. As a result, theENDScolumn is never less thanLAST_EXECUTED.EVENT_COMMENT事件的注释文本(如果有)。如果没有,则该值为空。The text of the comment, if the event has one. If not, this value is empty.
ORIGINATOR创建事件的 MySQL 服务器的服务器 ID;用于复制。如果在复制源上执行
ALTER EVENT语句,这个值可能会更新为执行该语句的服务器的服务器 ID。默认值为 0。The server ID of the MySQL server on which the event was created; used in replication. This value may be updated byALTER 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_CLIENT创建事件时
character_set_client系统变量的会话值。The session value of thecharacter_set_clientsystem variable when the event was created.COLLATION_CONNECTION创建事件时
collation_connection系统变量的会话值。The session value of thecollation_connectionsystem variable when the event was created.DATABASE_COLLATION事件关联的数据库的排序规则。The collation of the database with which the event is associated.
注意事项Notes
EVENTS是一个非标准的INFORMATION_SCHEMA表。EVENTSis a nonstandardINFORMATION_SCHEMAtable.EVENTS表中的时间显示使用事件时区、当前会话时区或 UTC,如 第 27.4.4 节,“事件元数据” 所述。Times in theEVENTStable are displayed using the event time zone, the current session time zone, or UTC, as described in Section 27.4.4, “Event Metadata”.有关
REPLICA_SIDE_DISABLED和ORIGINATOR列的更多信息,请参见 第 19.5.1.16 节,“已调用功能的复制”。For more information aboutREPLICA_SIDE_DISABLEDand theORIGINATORcolumn, see Section 19.5.1.16, “Replication of Invoked Features”.
示例Example
假设用户 'jon'@'ghidora' 创建了一个名为 e_daily 的事件,然后在几分钟后使用 ALTER
EVENT 语句对其进行修改,如下所示: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:
DELIMITER |
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.)
然后,该用户可以运行以下 SELECT 语句,并获得如下输出:This user can then run the following
SELECT statement, and obtain the
output shown:
mysql>SELECT * FROM INFORMATION_SCHEMA.EVENTSWHERE 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
事件信息也可以通过 SHOW EVENTS 语句获取。参见 第 15.7.7.19 节,“SHOW EVENTS 语句”。以下语句是等效的:Event information is also available from the
SHOW EVENTS statement. See
Section 15.7.7.19, “SHOW EVENTS Statement”. The following statements are
equivalent:
SELECT
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']