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.