Name
CREATE EVENT
Synopsis
CREATE [DEFINER = {'user'@'host'|CURRENT_USER}] EVENT
[IF NOT EXISTS] event
ON SCHEDULE
AT timestamp [+ INTERVAL count interval] |
EVERY count interval
[STARTS timestamp [+ INTERVAL count interval]]
[ENDS timestamp [+ INTERVAL count interval]]
[ON COMPLETION [NOT] PRESERVE]
[ENABLE|DISABLE|DISABLE ON SLAVE]
[COMMENT 'comment']
DO statementUse this statement to schedule the execution of an SQL statement at a specific time and date. Events may also be recurring. Although there are many options, the basic syntax is:
CREATE EVENTeventON SCHEDULE ATtimestampDOstatement
The event name you give may be any nonreserved word and is
case-insensitive. The DO clause can include any SQL
statement to be executed. A stored procedure can be passed here to
conveniently execute a set of SQL statements.
With the DEFINER clause, you can specify
the MySQL user and host to be used by MySQL for the event. This means
that the event may be created by a user with SUPER
privileges but executed by another user account in which privileges
are limited for security reasons. The IF NOT EXISTS
clause may be given to prevent errors from being returned if the event
has already been created.
For the required ON SCHEDULE AT clause,
include a specific time and date in the timestamp
format (yyyy-mm-dd hh:mm:ss). The time
given can be a string, a time function, or just
CURRENT_TIMESTAMP. You can also specify a time
relative to the timestamp given by adding a plus sign followed by the
keyword ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access