查看是否启用了Mysql event
mysql> select @@event_scheduler;
mysql> show variables like 'event_scheduler';
如果没有开启,开启它。
mysql> set GLOBAL event_scheduler=ON;
或
mysql> set GLOBAL event_scheduler=1;
创建event
create event e_test on schedule every 5 second starts timestamp '2010-01-12 23:22:00' enable do
select * from mysql.event;
修改event
alter event e_test on schedule every 1 day starts timestamp '2010-01-12 23:22:00' enable do
select * from mysql.event;
删除event
drop event e_test;
启用和禁用event
alter event e_test enable;
alter event e_test disable;
查看event
show events\G;
select * from INFORMATION_SCHEMA.EVENT;
SHOW EVENTS [FROM schema_name]
[LIKE 'pattern' | WHERE expr]
查看event创建脚本
SHOW CREATE EVENT event_name
show create event event_name\G
创建event语法
CREATE [DEFINER = { user | CURRENT_USER }]
EVENT
[IF NOT EXISTS]
event_name
ON SCHEDULE schedule
[ON COMPLETION [NOT] PRESERVE]
[ENABLE | DISABLE | DISABLE ON SLAVE]
[COMMENT ''comment'']
DO sql_statement;
schedule:
AT timestamp [+ INTERVAL interval]
| EVERY interval
[STARTS timestamp [+ INTERVAL interval]]
[ENDS timestamp [+ INTERVAL interval]]
interval:
quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}
修改event语法
ALTER EVENT event_name
[ON SCHEDULE schedule]
[RENAME TO new_event_name]
[ON COMPLETION [NOT] PRESERVE]
[COMMENT ''comment'']
[ENABLE | DISABLE]
[DO sql_statement]