Using a timer to invoke a stored procedure for MySQL--navicat client

Source: Internet
Author: User

1. Creating a stored procedure with a cursor

SQL creation:

Create PROCEDURE daily_max_avg_online () begindeclare 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:loopfetch 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;

NAVICAT Create:

1. Click Functions in the database--new function

2. Click Finish to enter the interface to create the stored procedure


3. Save (Ctrl+s)--> enter stored procedure name--Complete the creation of the stored procedure


2. Create a timer call stored procedure
1. Click Events--New events--Enter the interface--fill in the stored procedures that need to be called periodically
2. Set the timer task--set here once a day, start time is 2014-12-04 15:08:00

3. The constant global event_scheduler must be on or 1 for the timer to work .--Check whether the timer is turned onSHOW VARIABLES like '%event_scheduler% '; --Open timer 0:off 1:onSET GLOBAL event_scheduler = 1; or SET GLOBAL event_scheduler = on; Over

Stored procedure for calling MySQL using timers--navicat client

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.