我们如何修改现有的MySQL事件?
借助ALTER EVENT语句,我们可以修改现有的MySQL事件。我们可以更改事件的各种属性。ALTER EVENT具有以下语法-
ALTER EVENT event_nameON SCHEDULE schedule
ON COMPLETION [NOT] PRESERVE
RENAME TO new_event_name
ENABLE | DISABLE
DO
event_body
为了理解它,我们在下面举例说明-
示例
假设我们有一个事件如下-
mysql> Create event hello ON SCHEDULE EVERY 1 Minute DO INSERT INTO event_messages(message, generated_at) Values ('Alter event testing', NOW());mysql> select * from event_messages;
+----+---------------------+---------------------+
| ID | MESSAGE | Generated_at |
+----+---------------------+---------------------+
| 1 | Without Preserve | 2017-11-22 20:32:13 |
| 2 | With Preserve | 2017-11-22 20:35:12 |
| 3 | Alter event testing | 2017-11-22 21:08:37 |
+----+---------------------+---------------------+
3 rows in set (0.00 sec)
mysql> ALTER EVENT hello ON SCHEDULE EVERY 2 MINUTE;
上面的查询会将事件的时间表从1分钟更改为2分钟。下面的查询将更改事件的主体。
mysql> ALTER EVENT hello DO INSERT INTO event_messages(message,generated_at) VALUES('ALTERED',NOW());mysql> select * from event_messages;
+----+---------------------+---------------------+
| ID | MESSAGE | Generated_at |
+----+---------------------+---------------------+
| 1 | Without Preserve | 2017-11-22 20:32:13 |
| 2 | With Preserve | 2017-11-22 20:35:12 |
| 3 | Alter event testing | 2017-11-22 21:08:37 |
| 4 | Alter event testing | 2017-11-22 21:09:15 |
| 5 | ALTERED | 2017-11-22 21:11:15 |
+----+---------------------+---------------------+
5 rows in set (0.00 sec)
上面的结果集显示2分钟后我们收到了更改的消息。
以上是 我们如何修改现有的MySQL事件? 的全部内容, 来源链接: utcz.com/z/335186.html