Mariadb/mysql Event Usage Daquan

Source: Internet
Author: User

SHOW VARIABLES like ' Event_scheduler '; ==> query Whether the event is turned on

SET GLOBAL Event_scheduler = 1;==> Opens the event

set Event_scheduler is always on
in MY.CNF or My.ini, add event_scheduler=1 or mysqld.--event_scheduler=1

DROP event  if exists  event_name;==> But when an event is running, deleting the event does not cause the event to stop, and the event executes until it finishes.

When using the event, note that the timer is turned on on the main library, the timer is turned off from the library, the event trigger all actions are recorded binlog for master-slave synchronization, and the timer opening from the library is likely to cause the card library. After switching the main library, remember to turn on the timer on the new Main library.


CREATE EVENT [Ifnot EXISTS] Event_Name

On SCHEDULE SCHEDULE//at TIMESTAMP [+ INTERVAL INTERVAL] | Every INTERVAL [starts TIMESTAMP] [ENDS TIMESTAMP] INTERVAL 5  DAY 5天后

On completion [NOT] PRESERVE]

[ENABLE | DISABLE]

[COMMENT ' COMMENT ']

Do sql_statement;

< Span style= "Color:rgb (51,51,51); Font-family:arial;font-size:14px;line-height:26px;background-color:rgb ( 255,255,255); " >

< Span style= "Color:rgb (51,51,51); Font-family:arial;font-size:14px;line-height:26px;background-color:rgb ( 255,255,255); " >//per minute

DELIMITER//

CREATE Event Inserttable

On SCHEDULE every 1 MINUTE

Do INSERT into Test VALUES (Current_timestamp)

//

DELIMITER;

Specify the time of day

DELIMITER//

CREATE Event Inserttable

On SCHEDULE every 1 day starts ' 2012-09-26 14:55:00 '

Do INSERT into Test VALUES (Current_timestamp)

//

DELIMITER;


ALTER EVENT inserttable disable;==> temporarily stopped

SHOW processlist; ==> View ID

SHOW EVENTS; ==> View information

SELECT * from Mysql.event; ==> View more information

Alter event inserttable on SCHEDULE every 1 day starts ' 2012-09-26 15:19:00 ';==> modified

Actual case:

the number of each month 1 o'clock in the morning executes:
CREATE EVENT not EXISTS STAT
On SCHEDULE every 1 MONTH starts Date_add (Date_add (Date_sub (), Curdate Day (INTERVAL ()) – 1 day), Curdate 1 MONTH), INTERVAL 1 HOUR)
On completion PRESERVE ENABLE
Do
BEGIN
Multiple statements
END

This article is from the "Blue Sky" blog, make sure to keep this source http://shurk.blog.51cto.com/1134443/1746306

Mariadb/mysql Event Usage Daquan

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.