The event scheduler in MySQL is a new feature after MySQL 5.1. The database can be made, added, deleted, modified and manipulated in accordance with the specified time period. Equivalent to the unmanned scheduler in Linux crontab ( For the operation of the related crontab, see my Linux planning tasks. Avoid some data related timing tasks in the business operations layer, reduce the risk of operator misoperation, greatly shorten the workload to improve efficiency.
The following syntax is introduced first:
CREATE EVENT [IF not EXISTS] Event_Name
On SCHEDULE SCHEDULE
[on completion [NOT] PRESERVE]
[ENABLE | DISABLE]
[COMMENT ' COMMENT ']
Do sql_statement
Schedule
at TIMESTAMP [+ INTERVAL INTERVAL]
| Every INTERVAL [starts TIMESTAMP] [ENDS TIMESTAMP]
INTERVAL:
Quantity {Year | QUARTER | MONTH | Day | HOUR | MINUTE |
WEEK | SECOND | Year_month | Day_hour | Day_minute |
Day_second | Hour_minute | Hour_second | Minute_second}
Description: An optional item in brackets to specify how often the task executes. Specify the specific action to be performed by the DO clause.
Create a scheduled task each three seconds you want to insert a test data into a table. Examples are as follows:
(1) Create test table both:(note: Just in order to simulate the database password forgot to do the following database to stop operation, when you start to pay attention must be the process of mysqldkill off otherwise unable to start.)
Next create the test library, this example uses the table previously used for testing: t_time, create the following statement:
|
CREATE TABLE ' T_time ' ( |
|
' d ' date is DEFAULT NULL, |
|
' t ' time DEFAULT NULL, |
|
' DT ' datetime DEFAULT NULL, |
|
' UpdateTime ' timestamp not NULL DEFAULT current_timestamp COMMENT ' last update |
|
Room |
|
) Engine=innodb DEFAULT Charset=utf8; |
(2) Create Event Scheduler Event_insert_t_time
(3) To see if the event Scheduler was created successfully: A description was created successfully.
(4) After a few seconds there is no data in the view table.
(5) Check the status of the scheduler to see if it is turned on, (default is OFF)
(6) Open Scheduler
(7) View the data in the table
(8) Design Scheduler disabled
(9) If not, you can delete the Scheduler command as follows:
Drop event event_insert_t_time;
This article I original, welcome reprint reprint Please explain the source.
MySQL Event Scheduler