Home >Database >Mysql Tutorial >How do we modify existing MySQL events?
With the ALTER EVENT statement, we can modify existing MySQL events. We can change various properties of the event. The syntax of ALTER EVENT is as follows:
ALTER EVENT event_name ON SCHEDULE schedule ON COMPLETION [NOT] PRESERVE RENAME TO new_event_name ENABLE | DISABLE DO event_body
To understand it, we will give an example as follows-
Suppose we have an event as follows-
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)
The above query will change the event's schedule from 1 minute to 2 minutes. The following query will change the body of the event.
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)
The above result set shows that we received the changed message 2 minutes later.
The above is the detailed content of How do we modify existing MySQL events?. For more information, please follow other related articles on the PHP Chinese website!