mysql 定时器 启动 存储过程

来源:互联网 发布:滴定度的浓度算法 编辑:程序博客网 时间:2024/05/29 17:53

定时器的步骤

首先创建存储过程  == 》  然后定时任务中添加存储过程  ==》 查看定时器是否启动
使用的表及数据


表数据


创建存储过程

查看是否存在此存储过程
1.查看所有的存储过程
show procedure status;
2.根据数据库查看存储过程(dbname是数据库名)
select `name` from mysql.proc where db = 'dbname' and `type` = 'PROCEDURE'
删除存储过程(已加判断是否存在,可以查看之后再删除。以免影响数据库)
DROP PROCEDURE IF EXISTS set_now_upline_decoration_status;
创建存储过程
CREATE PROCEDURE set_now_upline_decoration_status()BEGINdeclare innoticeId INT default 0;select noticeId INTO innoticeId FROM notice WHERE uplineTime = now();IF innoticeId != 0THEN UPDATE notice SET noticeStatus=2 where noticeStatus =1;UPDATE notice SET noticeStatus=1 WHERE noticeId = innoticeId and noticeStatus = 2;END IF;END;

创建定时器

删除定时器
drop event if exists truncate_event;

创建定时器
create event truncate_eventon schedule every 1 seconddo call set_now_upline_decoration_status();

every 1 second(second是时间。可参照时间:1 second , 3 minute , 5 hour ,9 day , 1 month , 1 quarter (季度) , 1 year )


原创粉丝点击