借助 ALTER EVENT 語句,我們可以修改現有的 MySQL 事件。我們可以更改事件的各種屬性。 ALTER EVENT 的語法如下:
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 事件?的詳細內容。更多資訊請關注PHP中文網其他相關文章!