一、查询事件状态,mysql查看事件是否开启,设置启动时自动开启方法
1.查看事件是否开启
SHOW VARIABLES LIKE ‘event_scheduler’
2.设置当前事件开启
SET GLOBAL event_scheduler = 1;
或
SET GLOBAL event_scheduler = ON;
3.设置事件在mysql启动时自动开启方法
1. 开启事件,通过动态参数修改:SET GLOBAL event_scheduler = ON;
2. 在my.cnf(Linux系统)或 my.ini(Windows系统)中添加event_scheduler=ON。(如果没有添加的话,mysql重启事件又会回到原来的状态)
-- 删除日记中超过一百万的旧数据
create procedure pro_dellog()
BEGIN
DECLARE tasklogrownum int DEFAULT 0;
DECLARE comlogrownum int DEFAULT 0;
select count(*) into tasklogrownum from tab_task_info_log;
if tasklogrownum > 1000000 THEN
set tasklogrownum = tasklogrownum - 1000000;
DELETE FROM tab_task_info_log ORDER BY LogTime LIMIT tasklogrownum;
END IF;
select co