你是否对获得一个MySQL事件的实际操作感到十分头疼?如果是这样子的话,以下的文章将会给你相应的解决方案,以下的文章主要是介绍获得一个MySQL事件的方案,以下就是相关内容的具体描述。
操作系统中的计划任务(WINDOWS)或CRONTABL(LINUX/UNIX)
MySQL版本5.1以上,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
MySQL事件中定时delete
- 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)
这个建议用MySQL本上的event来实现; 也可以用操作系统的计划任务来处理; 或自己写个程序用定时器来触发。以上的相关内容就是对一个MySQL事件的介绍,望你能有所收获。
【编辑推荐】