ALTER
    [DEFINER = user]
    EVENT event_name
    [ON SCHEDULE schedule]
    [ON COMPLETION [NOT] PRESERVE]
    [RENAME TO new_event_name]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'string']
    [DO event_body]
The ALTER EVENT statement changes one or more of the characteristics of an existing event without the need to drop and recreate it. ALTER EVENT语句更改现有事件的一个或多个特征,而无需删除并重新创建它。The syntax for each of the DEFINER, ON SCHEDULE, ON COMPLETION, COMMENT, ENABLE / DISABLE, and DO clauses is exactly the same as when used with CREATE EVENT. DEFINER、ON SCHEDULE、ON COMPLETION、COMMENT、ENABLE/DISABLE和DO子句的语法与CREATE EVENT使用时完全相同。(See Section 13.1.13, “CREATE EVENT Statement”.)(请参阅第13.1.13节,“CREATE EVENT语句”。)
Any user can alter an event defined on a database for which that user has the 任何用户都可以更改该用户具有EVENT privilege. EVENT权限的数据库上定义的事件。When a user executes a successful 当用户执行成功的ALTER EVENT statement, that user becomes the definer for the affected event.ALTER EVENT语句时,该用户将成为受影响事件的定义者。
ALTER EVENT works only with an existing event:ALTER EVENT仅适用于现有事件:
mysql>ALTER EVENT no_such_event>ON SCHEDULE>EVERY '2:3' DAY_HOUR;ERROR 1517 (HY000): Unknown event 'no_such_event'
In each of the following examples, assume that the event named 在以下每个示例中,假设名为myevent is defined as shown here:myevent的事件定义如下所示:
CREATE EVENT myevent
    ON SCHEDULE
      EVERY 6 HOUR
    COMMENT 'A sample comment.'
    DO
      UPDATE myschema.mytable SET mycol = mycol + 1;
The following statement changes the schedule for 下面的语句将myevent from once every six hours starting immediately to once every twelve hours, starting four hours from the time the statement is run:myevent的计划从立即开始的每六小时一次更改为每十二小时一次,从语句运行的四小时开始:
ALTER EVENT myevent
    ON SCHEDULE
      EVERY 12 HOUR
    STARTS CURRENT_TIMESTAMP + INTERVAL 4 HOUR;
It is possible to change multiple characteristics of an event in a single statement. 可以在一条语句中更改事件的多个特征。This example changes the SQL statement executed by 本例将myevent to one that deletes all records from mytable; it also changes the schedule for the event such that it executes once, one day after this ALTER EVENT statement is run.myevent执行的SQL语句更改为从mytable中删除所有记录的SQL语句;它还更改事件的计划,以便在运行ALTER EVENT语句一天后执行一次。
ALTER EVENT myevent
    ON SCHEDULE
      AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
    DO
      TRUNCATE TABLE myschema.mytable;
Specify the options in an 在ALTER EVENT statement only for those characteristics that you want to change; omitted options keep their existing values. ALTER EVENT语句中仅为要更改的特征指定选项;省略的选项保留其现有值。This includes any default values for 这包括CREATE EVENT such as ENABLE.CREATE EVENT的任何默认值,例如ENABLE。
To disable 要禁用myevent, use this ALTER EVENT statement:myevent,请使用以下ALTER EVENT语句:
ALTER EVENT myevent
    DISABLE;
The ON SCHEDULE clause may use expressions involving built-in MySQL functions and user variables to obtain any of the timestamp or interval values which it contains. ON SCHEDULE子句可以使用包含内置MySQL函数和用户变量的表达式来获取它包含的任何timestamp或interval。You cannot use stored routines or loadable functions in such expressions, and you cannot use any table references; however, you can use 不能在此类表达式中使用存储例程或可加载函数,也不能使用任何表引用;但是,您可以使用SELECT FROM DUAL. SELECT FROM DUAL。This is true for both 对于ALTER EVENT and CREATE EVENT statements. ALTER EVENT和CREATE EVENT语句都是如此。References to stored routines, loadable functions, and tables in such cases are specifically not permitted, and fail with an error (see Bug #22830).在这种情况下,不允许引用存储的例程、可加载的函数和表,并且会因错误而失败(参见Bug#22830)。
Although an 虽然在ALTER EVENT statement that contains another ALTER EVENT statement in its DO clause appears to succeed, when the server attempts to execute the resulting scheduled event, the execution fails with an error.DO子句中包含另一个ALTER EVENT语句的ALTER EVENT语句似乎成功,但当服务器尝试执行生成的计划事件时,执行失败并出现错误。
To rename an event, use the 要重命名事件,请使用ALTER EVENT statement's RENAME TO clause. ALTER EVENT语句的RENAME TO子句。This statement renames the event 此语句将事件myevent to yourevent:myevent重命名为yourevent:
ALTER EVENT myevent
    RENAME TO yourevent;
You can also move an event to a different database using 您还可以使用ALTER EVENT ... RENAME TO ... and db_name.event_nameALTER EVENT ... RENAME TO ...和db_name.event_name记号法将事件移至其它数据库,如下所示:
ALTER EVENT olddb.myevent
    RENAME TO newdb.myevent;
To execute the previous statement, the user executing it must have the 要执行上一条语句,执行该语句的用户必须对EVENT privilege on both the olddb and newdb databases.olddb和newdb数据库都具有EVENT权限。
There is no 没有RENAME EVENT statement.RENAME EVENT语句。
The value 在复制副本上使用值DISABLE ON SLAVE is used on a replica instead of ENABLE or DISABLE to indicate an event that was created on the replication source server and replicated to the replica, but that is not executed on the replica. DISABLE ON SLAVE,而不是ENABLE或DISABLE,以指示在复制源服务器上创建并复制到复制副本,但未在复制副本上执行的事件。Normally, 正常情况下,根据需要自动设置DISABLE ON SLAVE is set automatically as required; however, there are some circumstances under which you may want or need to change it manually. DISABLE ON SLAVE(从机禁用);但是,在某些情况下,您可能希望或需要手动更改它。See Section 17.5.1.16, “Replication of Invoked Features”, for more information.有关更多信息,请参阅第17.5.1.16节,“调用功能的复制”。