记录下自己写的MySQL简单存储过程和定时任务
统计有多少个app
/*应用统计存储过程*/
/*输入参数appStatus:应用的状态*/
DELIMITER $$
CREATE PROCEDURE `appStat`(IN appStatus int)
BEGIN
declare countNum int;
SELECT
COUNT(*)
INTO countNum FROM
app_info
WHERE
app_info.status = appStatus;
/*统计结果插入统计表*/
insert into app_stats(quantity,stat_time,stat_type,status) values(countNum,now(),1,appStatus);
END$$
DELIMITER ;
统计定时任务
/*应用统计定时任务*/
set global event_scheduler =1;/*开启定时任务*/
create event if not exists e_app
on schedule every 1 day starts '2017-01-09 00:00:00' /*每天执行一次*/
on completion preserve /*永久有效*/
do call appStat(0); /*调存储过程*/
停止和删除定时任务
关闭定时任务:
alter event e_app ON COMPLETION PRESERVE DISABLE;
开启定时任务:
alter event e_test ON COMPLETION PRESERVE ENABLE;
删除定时任务:
DROP EVENT IF EXISTS e_test;