mysql-Scheduled Task (event)

Source: Internet
Author: User

Tag:mysql    timing    

Before deleting data or changing data is to write a script on the server run timed tasks, Crontab wrote a lot of tasks, mysql 5.1 after the support of the incident can be very convenient to carry out; For example, I want to clear the clients table every night 23 o'clock. See if MySQL turns on event;show variables like  ' Event_scheduler '  ; open Set global event_ scheduler =1; Create Event # change;  to $$  on cmd command line delimiter $ $CREATE   EVENT  ' clients ' on  SCHEDULE EVERY 1 DAY STARTS  ' 2017-10-13 23:00:00 '  DO BEGIN     #干你想干的事情  insert delete update can   truncate table clients; end $ $DELIMITER  ;#  Daily execution is 1 day   weekly  1 week   hourly  1  Hour  1 minute View Event show events; If you want to set a few days later and do not want to calculate the time   such as 5 days after the start of execution delimiter $ $CREATE   EVENT  ' clients ' on schedule every 1 day current_timestamp+  interval 5 day do begin    #干你想干的事情  insert delete update can   truncate table clients; End $ $DELIMITER  ; If   stops after 5 days   add endsdelimiter $ $CREATE   EVENT  ' clients ' on  schedule every 1 day ends endscurrent_timestamp+ interval 5 day  DO BEGIN    #干你想干的事情  insert delete update can   truncate  table clients; end $ $DELIMITER  ;


mysql-Scheduled Task (event)

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.