ALTER EVENT event_name
ON 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());
Query OK, 0 rows affected (0.00 sec)
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;
Query OK, 0 rows affected (0.00 sec)
登录后复制
上述查询会将事件的时间表从 1 分钟更改为 2 分钟。下面的查询将更改事件的正文。
mysql> ALTER EVENT hello DO INSERT INTO event_messages(message,generated_at) VALUES('ALTERED',NOW());
Query OK, 0 rows affected (0.00 sec)
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 事件?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!