Mysql事件的使用

小豆苗 1年前 ⋅ 828 阅读

1. 创建事件

语法:

CREATE EVENT event_name
ON SCHEDULE schedule
ON COMPLETION [NOT] PRESERVE
ENABLE | DISABLE
DO
event_body

示例:

CREATE EVENT `test`.`EventInsert` ON SCHEDULE AT CURRENT_TIMESTAMP DO insert into test.temp_data values(0, "aaaaaa", "aaaaaa", "2023", 0);

2. 修改事件

语法:

ALTER EVENT event_name
ON SCHEDULE schedule
ON COMPLETION [NOT] PRESERVE
RENAME TO new_event_name
ENABLE | DISABLE
DO
event_body

示例:

ALTER EVENT `test`.`EventInsert` ON SCHEDULE AT CURRENT_TIMESTAMP DISABLE DO insert into test.temp_data values(0, "aaaaaa", "aaaaaa", "2023", 0);

3. 启用/禁用事件

语法:

ALTER EVENT event_name
ON SCHEDULE schedule
ON COMPLETION [NOT] PRESERVE
RENAME TO new_event_name
ENABLE | DISABLE
DO
event_body

示例:

启用:

ALTER EVENT `test`.`EventInsert` ON SCHEDULE AT CURRENT_TIMESTAMP ENABLE DO insert into test.temp_data values(0, "aaaaaa", "aaaaaa", "2023", 0);

禁用:

ALTER EVENT `test`.`EventInsert` ON SCHEDULE AT CURRENT_TIMESTAMP DISABLE DO insert into test.temp_data values(0, "aaaaaa", "aaaaaa", "2023", 0);

4. 删除事件:

语法:

DROP EVENT [IF EXISTS] event_name

示例:

DROP EVENT IF EXISTS `test`.`EventInsert`;

 


全部评论: 0

    我有话说: