你是否對獲得一個MySQL事件的實際操作感到十分頭疼?如果是這樣子的話,以下的文章將會給你相應的解決方案,以下的文章主要是介紹獲得一個MySQL事件的方案,以下就是相關內容的具體描述。
操作系統中的計劃任務WINDOWS)或CRONTABLLINUX/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事件的介紹,望你能有所收獲。