Introduction to the correct running solution of MySQL events

Source: Internet
Author: User

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

 
 
  1. CREATE   
  2. [DEFINER = { user | CURRENT_USER }]   
  3. EVENT   
  4. [IF NOT EXISTS]   
  5. event_name   
  6. ON SCHEDULE schedule   
  7. [ON COMPLETION [NOT] PRESERVE]   
  8. [ENABLE | DISABLE | DISABLE ON SLAVE]   
  9. [COMMENT 'comment']   
  10. DO sql_statement;   
  11. schedule:   
  12. AT timestamp [+ INTERVAL interval] ...   
  13. | EVERY interval   
  14. [STARTS timestamp [+ INTERVAL interval] ...]   
  15. [ENDS timestamp [+ INTERVAL interval] ...]   
  16. interval:   
  17. quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |   
  18. WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |   
  19. DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}   
  20. MySQL> SELECT NOW();   
  21. +---------------------+   
  22. | NOW() |   
  23. +---------------------+   
  24. | 2006-02-10 23:59:01 |   
  25. +---------------------+   
  26. 1 row in set (0.04 sec)   
  27.  
  28. MySQL> CREATE EVENT e_totals   
  29. -> ON SCHEDULE AT '2006-02-10 23:59:00'   
  30. -> DO INSERT INTO test.totals VALUES (NOW());   
  31. Query OK, 0 rows affected, 1 warning (0.00 sec)   
  32. MySQL> SHOW WARNINGS\G   
  33. *************************** 1. row ***************************   
  34. Level: Note   
  35. Code: 1588   
  36. Message: Event execution time is in the past and ON COMPLETION NOT   
  37. PRESERVE is set. The event was dropped immediately after   
  38. creation.  
  39. create event   

Scheduled delete in MySQL events

 
 
  1. MySQL> CREATE EVENT e_totals   
  2. -> ON SCHEDULE AT '2006-02-10 23:59:00'   
  3. -> DO INSERT INTO test.totals VALUES (NOW()); Query OK, 0 rows affected, 1 warning (0.00 sec)  
  4. MySQL> CREATE EVENT  
  5. -> event_name  
  6. -> ON SCHEDULE EVERY 1 DAY STARTS '2009-09-20 23:40:00'  
  7. -> DO delete from t2;  
  8. Query OK, 0 rows affected (0.14 sec)  
  9.  

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.

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.