Use the mysql event scheduler to periodically delete binlog

  • 2020-06-12 10:48:00
  • OfStack

MySQL's event scheduler is accurate to one task per second and is ideal for applications that require real-time data (e.g., stocks, odds, scores, etc.).
Check to see if this feature is enabled:
SELECT @@event_scheduler;

Before using this feature, you must ensure that event_scheduler is enabled and executable:
SET GLOBAL event_scheduler = 1;

Or we can add event_scheduler = 1 to the configuration my.cnf file
Then write an event for binlog deletion. Set the day check and delete the binlog file every 4 days before.
CREATE EVENT purge_binlog ON SCHEDULE EVERY 1 DAY DO PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 4 DAY);

You can view timed events by executing the following statement:
SELECT *  FROM information_schema.EVENTS; 

You can see the job information in the corresponding library, where the LAST_EXECUTED field reflects the last execution time of the corresponding job.

Related articles: