ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 【MySQL】使用event 的具体 案例

【MySQL】使用event 的具体 案例

原创 Linux操作系统 作者:杨奇龙 时间:2013-04-04 13:47:50 0 删除 编辑
前一篇文章介绍了 event 用法,本文介绍一个实际的使用案例
1 首先创建一个存储过程 删除指定时间之前的数据。
delimiter //
CREATE  PROCEDURE `proc_del_response_per_day`(in com_num int , in push_time datetime )
begin
    declare curid bigint ;
    DECLARE rowid bigint ;
    declare no_more_departments int ;
    declare curs cursor for
        select response_per_day_id
        from
            response_per_day
        WHERE
            gmt_created < push_time ;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_departments = 1;
    SET no_more_departments=0;
    set rowid = 1 ;
    set autocommit = 0 ;
    open curs ;
    REPEAT
        fetch curs into curid ;
        delete from response_per_day where response_per_day_id = curid ;
        set rowid = rowid + 1 ;
        if rowid % com_num = 0
        then
            commit;
        end if ;
    UNTIL no_more_departments
    END REPEAT;
    commit ;
    close curs ;
end;
//
delimiter ; 

创建一个定时器每个一个月调度一次

create evnet  e_call_proc_del_rpd
        on schedule every 1 month
        on completion  preserve
        do call(200,now());

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22664653/viewspace-757744/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
MySQL DBA NoSQL DEVOPS

注册时间:2009-10-07

  • 博文量
    1026
  • 访问量
    8205979