Use the mysql event scheduler to regularly Delete binlog

Source: Internet
Author: User

The MySQL event scheduler can execute a task exactly every second. It is suitable for applications with high real-time data requirements (such as stocks, odds, and scores.
First, check whether this function is Enabled:
Copy codeThe Code is as follows: SELECT @ event_scheduler;
Before using this function, make sure that event_scheduler is enabled. You can execute:
Copy codeThe Code is as follows: set global event_scheduler = 1;
Or we can add event_scheduler = 1 to the my. cnf file.
Then, write an event to delete the binlog. Set the daily check and delete the binlog file four days ago.
Copy codeThe Code is as follows: create event purge_binlog on schedule every 1 day do purge master logs before DATE_SUB (NOW (), INTERVAL 4 DAY );
To view scheduled events, run the following statement:
Copy codeThe Code is as follows: SELECT * FROM information_schema.EVENTS;
You can see the job information in the corresponding database. The LAST_EXECUTED field reflects the last execution time of the corresponding job.

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.