MySQL lets a stored procedure timed job Code _mysql

Source: Internet
Author: User
Tags create database
1, in MySQL to establish a database test1

Statement: CREATE DATABASE Test1

2. CREATE TABLE Examinfo

CREATE TABLE Examinfo (
ID int auto_increment NOT NULL,
Endtime datetime,
Primary KEY (ID)
);

3 Inserting data:

INSERT into Examinfo values (' 1 ', ' 2011-4-23 23:26:50 ');

4 Create stored Procedure test

CREATE PROCEDURE Test ()
BEGIN
Update Examinfo SET endtime = Now () WHERE id = 1;
End;

5. Create Event E_test
Copy Code code as follows:

CREATE EVENT if not exists e_test
On schedule every second
On completion Preserve
Do call Test ();


6, check whether the event is open: Show variables like '%sche% ';
To open the event plan: set global event_scheduler=1;
Shutdown Event Task: Alter event e_test on completion PRESERVE DISABLE;
Account opening event task: Alter event e_test on completion PRESERVE ENABLE;

7, run the query results can appear the desired results.

The results appear as follows:
Raw data:

After a period of time to query the data:

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.