Use a timer to call the mysql stored procedure.

Source: Internet
Author: User

Use a timer to call the mysql stored procedure.
1. Use a cursor to create a stored procedure

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 creation:

1. Click functions in the database --> Create Function

 

2. Click Finish all the way to go to the storage process creation interface.


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


2. Create a timer to call the Stored Procedure
1. Click Event --> Create event --> enter the interface --> enter the stored procedure that needs to be called regularly
2. Set the scheduled task. Here, the task is set to run once a day and the start time is 15:08:00.

3. the constant GLOBAL event_scheduler of MySQL must be on or 1 -- check whether the timer show variables like '% event_scheduler %' is enabled; -- enable the timer 0: off 1: on set global event_scheduler = 1; or set global event_scheduler = ON; Over

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.