数据库
首页 > 数据库> > MySQL-事件EVENT-时间定时器

MySQL-事件EVENT-时间定时器

作者:互联网

应用场景:一般用于在某一特定的时间点,触发相关的SQL语句或存储过程。

 

查看定时器开启状态:

SHOW VARIABLES LIKE 'event_scheduler';

开启定时器:0为OFF,1为ON

SET GLOBAL event_scheduler = 1;

关闭定时器:

SET GLOBAL event_scheduler = 0;

创建事件语法:

CREATE EVENT [IF NOT EXISTS] event_name

ON SCHEDULE schedule

[ON COMPLETION [NOT] PRESERVE]

[ENABLE | DISABLE | DISABLE ON SLAVE]

[COMMENT 'comment']

DO sql_statement;

注:

示例:

delimiter //
-- 定义一个事件,每隔一分钟,往member表中插入一条记录
CREATE EVENT IF NOT EXISTS event_insert_member
ON SCHEDULE EVERY 1 MINUTE
ON COMPLETION PRESERVE ENABLE DO
BEGIN
INSERT INTO member(mobilePhone,pwd) VALUES('18852145214','123');
END//
delimiter ;

 

 

 

标签:PRESERVE,定时器,EVENT,ENABLE,scheduler,MySQL,event
来源: https://www.cnblogs.com/huorong/p/15689068.html