MySql定时任务
stored procedure
创建
create procedure sp_name()
begin
………
end
调用
call sp_name()
注意:存储过程名称后面必须加括号,哪怕该存储过程没有参数传递
删除
drop procedure sp_name
其他
1.show procedure status
显示数据库中所有存储的存储过程基本信息,包括所属数据库,存储过程名称,创建时间等
2.show create procedure sp_name
显示某一个存储过程的详细信息
例子:
CREATE PROCEDURE `bag_app_flow`()
insert into bag_app_flow
select pid,avg(in_speed),avg(out_speed),max(log_time) log_time
from bag_app_flow_raw
where hour(now()) - hour(log_time) = 1
group by pid,date_format(log_time,'%Y-%m-%d %H');
--------------
event
使用下列的任意一句开启计划任务:
SET GLOBAL event_scheduler = ON;
SET @@global.event_scheduler = ON;
SET GLOBAL event_scheduler = 1;
SET @@global.event_scheduler = 1;
Event Scheduler创建的基本语法是:
CREATE EVENT
[IF NOT EXISTS]
event_name
ON SCHEDULE schedule
[ON COMPLETION [NOT] PRESERVE]
[ENABLE | DISABLE]
[COMMENT 'comment']
DO sql_statement
如果要调用procedure
call sp_name() ,如
create event flow_job
on schedule every 1 hour
starts '2009-12-26 18:06:00'
do
call bag_ip_flow();
如果有多个procedures,则要加begin...end,如
create event flow_job
on schedule every 1 hour
starts '2009-12-26 18:06:00'
do
begin
call bag_app_flow();
call bag_ip_flow();
call bag_ip_group_flow();
end