Home > Database > Mysql Tutorial > body text

使用定时器调用mysql的存储过程--navicat客户端_MySQL

WBOY
Release: 2016-06-01 13:01:07
Original
2113 people have browsed it

1.使用游标创建存储过程

SQL创建:

 

create PROCEDURE daily_max_avg_online()
BEGIN
declare max_online int;
declare avg_online int;
declare time TIMESTAMP;
declare cur cursor for 
select MAX(online_num),round(avg(online_num)),
DATE_FORMAT(statistical_time ,'%y-%m-%d') 
from real_time_online_statistics 
group by DATE_FORMAT(statistical_time ,'%y-%m-%d');

open cur;
cur:loop
FETCH cur into max_online,avg_online,time;

insert into daily_max_avg_online_statistics(id,max_online_num,avg_online_num,statistical_time) 
values(UUID(),max_online,avg_online,time); 
end loop cur;
close cur;

END;
Copy after login

 

Navicat创建:

1,.点击数据库中的函数 --> 新建函数

\

 

2.一路点击完成,进入创建存储过程的界面

\

3.保存(Ctrl+S) -- > 输入存储过程名称 --> 完成存储过程的创建

2.创建定时器调用存储过程


1.点击事件 --> 新建事件 --> 进入界面 --> 填写需要定时调用的存储过程

\
2.设置定时任务 -- 这里设置每天一次,开始时间为 2014-12-04 15:08:00


\
3.要使定时起作用MySQL的常量GLOBAL event_scheduler必须为on或者是1 -- 查看是否开启定时器 SHOW VARIABLES LIKE "%event_scheduler%'; -- 开启定时器 0:off 1:on SET GLOBAL event_scheduler = 1; 或 SET GLOBAL event_scheduler = ON; Over   

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!