MySQL Event and time operation

Source: Internet
Author: User

1. How long is the distance from the current execution

DELIMITER $$

ALTER definer= ' admin ' @ '% ' EVENT ' epnrupdatestatusagain ' on SCHEDULE every 1 day starts ' 2015-07-24 14:45:00 ' on completion PRESERVE ENABLE do BEGIN
UPDATE diyfare. ' PNR '
SET diyfare. ' PNR '. ' Status ' =2
WHERE diyfare. ' PNR '. ' Status '! = 2
And now () between Date_sub (Diyfare "PNR". ' Deadline ', INTERVAL 1 day) and Diyfare. ' PNR '. ' Deadline ';
end$$

DELIMITER;

Date_sub ago

After Date_add

Gets the current time SELECT now ();

2. EVENT

--Check whether the timer is turned on

Show variables like '%sche% ';

--Turn on timer

Set global Event_scheduler = 1;

--changing separators
Mysql> delimiter//

--Create a stored procedure
Mysql> CREATE PROCEDURE pro_lqy_test_insert_23 ()
Begin
Insert into Lqy_test (title,content,createtime) VALUES (' title titles ', ' Con
Tent contents ', now ());
end//
Query OK, 0 rows Affected (0.00 sec)

--creation of events, executed 15:15:00 every day

Mysql> Create Event Event_lqy_test_insert_23
-On schedule
-Every 1 day starts ' 2012-04-24 15:15:00 '
Do-Call pro_lqy_test_insert_23 ()//
Query OK, 0 rows Affected (0.00 sec)

Mysql> delimiter;

--Start Event
Mysql> Alter event event_lqy_test_insert_23 on
-Completion preserve enable;
Query OK, 0 rows Affected (0.00 sec)

--Close Event

Mysql> Alter event event_lqy_test_insert_23 on
Completion preserve disable;
Query OK, 0 rows Affected (0.00 sec)

MySQL Event and time operation

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.