Are you very worried about the actual operation of getting a MySQL event? If this is the case, the following articles will provide you with corresponding solutions. The following articles mainly describe how to obtain a MySQL event. The following describes the specific content.
WINDOWS) or CRONTABLLINUX/UNIX)
MySQL version 5.1 or later, create event
- CREATE
- [DEFINER = { user | CURRENT_USER }]
- EVENT
- [IF NOT EXISTS]
- event_name
- ON SCHEDULE schedule
- [ON COMPLETION [NOT] PRESERVE]
- [ENABLE | DISABLE | DISABLE ON SLAVE]
- [COMMENT 'comment']
- DO sql_statement;
- schedule:
- AT timestamp [+ INTERVAL interval] ...
- | EVERY interval
- [STARTS timestamp [+ INTERVAL interval] ...]
- [ENDS timestamp [+ INTERVAL interval] ...]
- interval:
- quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
- WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
- DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}
- MySQL> SELECT NOW();
- +---------------------+
- | NOW() |
- +---------------------+
- | 2006-02-10 23:59:01 |
- +---------------------+
- 1 row in set (0.04 sec)
-
- MySQL> CREATE EVENT e_totals
- -> ON SCHEDULE AT '2006-02-10 23:59:00'
- -> DO INSERT INTO test.totals VALUES (NOW());
- Query OK, 0 rows affected, 1 warning (0.00 sec)
- MySQL> SHOW WARNINGS\G
- *************************** 1. row ***************************
- Level: Note
- Code: 1588
- Message: Event execution time is in the past and ON COMPLETION NOT
- PRESERVE is set. The event was dropped immediately after
- creation.
- create event
Scheduled delete in MySQL events
- MySQL> CREATE EVENT e_totals
- -> ON SCHEDULE AT '2006-02-10 23:59:00'
- -> DO INSERT INTO test.totals VALUES (NOW()); Query OK, 0 rows affected, 1 warning (0.00 sec)
- MySQL> CREATE EVENT
- -> event_name
- -> ON SCHEDULE EVERY 1 DAY STARTS '2009-09-20 23:40:00'
- -> DO delete from t2;
- Query OK, 0 rows affected (0.14 sec)
-
We recommend that you use the event in MySQL to implement this. You can also use the scheduled task of the operating system to process it. Or you can write a program to trigger it with a timer. The above content is an introduction to a MySQL event. I hope you will get some benefits.