一、普通事件:直接执行语句:
DROP EVENT IF EXISTS job_insertgood;
DELIMITER $$
CREATE EVENT job_insertgood
ON SCHEDULE EVERY 10 SECOND
DO
BEGIN
INSERT INTO goods (name,num) VALUES (now(),1);
END$$
DELIMITER ;
二、事件:调用存储过程
DROP EVENT IF EXISTS job_callProcedure;
DELIMITER $$
CREATE EVENT job_callProcedure
ON SCHEDULE EVERY 10 SECOND
DO
BEGIN
CALL procedureName();
END$$
DELIMITER ;
三、开启事件(定时任务):
1、查看
SELECT @@event_scheduler;
或者
SHOW VARIABLES LIKE 'event%'
2、设置:
set GLOBAL event_scheduler = 1;
或者
SET GLOBAL event_scheduler = ON;