📅  最后修改于: 2023-12-03 15:23:13.646000             🧑  作者: Mango
在 MySQL 中,事件(Event)是一种计划任务,可以用来指定在特定时间自动执行某些操作,例如备份数据库或执行定期维护等任务。在本文中,我们将介绍如何在 MySQL 中显示所有的事件计划。
在 MySQL 中,可以使用 SHOW EVENTS 命令来显示所有的事件计划。示例代码如下:
SHOW EVENTS;
执行以上代码后,MySQL 会返回所有事件计划的详细信息,例如事件名称、计划执行时间、执行语句等信息。返回结果示例:
*************************** 1. row ***************************
Db: test
Name: event1
Definer: root@localhost
Time zone: SYSTEM
Type: RECURRING
Execute at: NULL
Interval value: 1
Interval field: HOUR
Starts: 2021-11-11 00:00:00
Ends: NULL
Status: ENABLED
Originator: 1
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
Database Collation: utf8mb4_0900_ai_ci
除了使用 SHOW EVENTS 命令,我们还可以在 information_schema 数据库中查询所有的事件计划。查询代码如下:
SELECT * FROM information_schema.events;
执行以上查询语句后,MySQL 会返回所有事件计划的详细信息,包括事件名称、计划执行时间、执行语句等信息。返回结果示例:
+----------------+--------------+-----------------+----------------+-------------+--------+-------------+-----------+---------------+---------------+------------+---------------------+---------------------+--------------+--------------+-------------------+--------------+------------------------+------------------------+-------------------+---------------------+---------------------+-----------------+----------------------+----------------------+-------------------+------------------------+------------------------+---------------------+---------------------+--------------------------+------------------------+
| EVENT_CATALOG | EVENT_SCHEMA | EVENT_NAME | DEFINER | TIME_ZONE | EVENT_BODY | EVENT_TYPE | EXECUTE_AT | INTERVAL_VALUE | INTERVAL_FIELD | SQL_MODE | STARTS | ENDS | STATUS | ON_COMPLETION | CREATED | LAST_ALTERED | LAST_EXECUTED | EVENT_COMMENT | ORIGINATOR | CHARACTER_SET_CLIENT | COLLATION_CONNECTION | DATABASE_COLLATION | DEFINER_CHARACTER_SET | DEFINER_COLLATION | LAST_ALTERED_VERSION | LAST_EXECUTED_VERSION | LAST_EXECUTION_TIME | STARTS_IMMEDIATELY |
+----------------+--------------+-----------------+----------------+-------------+--------+-------------+-----------+---------------+---------------+------------+---------------------+---------------------+--------------+--------------+-------------------+--------------+------------------------+------------------------+-------------------+---------------------+---------------------+-----------------+----------------------+----------------------+-------------------+------------------------+------------------------+---------------------+---------------------+--------------------------+------------------------+
| def | test | event1 | root@localhost | SYSTEM | SQL | RECURRING | NULL | 1 | HOUR | STRICT_ALL | 2021-11-11 00:00:00 | NULL | ENABLED | NOT APPLICABLE | 2021-11-11 00:00:00 | NULL | 2021-11-11 00:00:00.000 | This is a test event. | root@localhost | utf8mb4 | utf8mb4_general_ci | utf8mb4_0900_ai_ci | utf8mb4 | utf8mb4_general_ci | 1.1 | 1.0 | 2021-11-11 00:00:00.000 | NO |
+----------------+--------------+-----------------+----------------+-------------+--------+-------------+-----------+---------------+---------------+------------+---------------------+---------------------+--------------+--------------+-------------------+--------------+------------------------+------------------------+-------------------+---------------------+---------------------+-----------------+----------------------+----------------------+-------------------+------------------------+------------------------+---------------------+---------------------+--------------------------+------------------------+
以上就是在 MySQL 中显示所有事件计划的两种方法。想要管理和编辑事件计划,可以在 MySQL 客户端中使用 CREATE EVENT、ALTER EVENT 和 DROP EVENT 等命令来完成。更多信息可以在 MySQL 官方文档中查阅。