Mysql binlog set the expiration time and automatically deleted

Problem: 
Mysql database for business reasons, the amount of data growing rapidly, binlog log will increase more, take up most of the disk space. 

Solution: 
For space-saving reasons, can remove the extra binary logs, and set up a regular deletion. 

1 , the expiration time binlog See 
MySQL > Show Variables like  ' expire_logs_days ' ; or 
MySQL >  SELECT  @@ Global .expire_logs_days;
 + - ---------------- + ----- - + 
| variable_name | Value | 
+ - ---------------- + ------- + 
| expire_logs_days |  0  | 
+ - ------ + ------- + ---------- 
. 1 Rowin  the SET ( 0.00 sec) 

expire_logs_days = 0 : means all binlog log forever will not fail, will not be automatically deleted; 

the current demand, just log for seven days, and the remaining log packaged, compressed backup to another location: 

modifications: 
permanent (after reboot force): 
: (the window system environment, if the environment is Linux, the file is modified my.cnf) modify the configuration files my.ini file 
in [ mysqld ] increase following the tag 
expire_logs_days = . 7 
max_binlog_size = 500M 

after setting not immediately clear, the trigger condition is: 
binlog size exceeds max_binlog_size 
performed manually flush logs 
restart (MySQL will file for new a new record binlog) 

In order to make it work, we need to execute flush logs. 

MySQL > the flush logs; 
Query the OK, 0 rows affected, 64Represents warnings ( 0.16 sec 

if binlog very much, Do not set this parameter, it may lead io contention, this time using the purge command can be cleared: 

the previous bin.000055 binlog cleared: 
MySQL > purge binary logs to  ' bin. 000055 ' ; 

will be cleared away before the specified time binlog: 
MySQL > purge binary logs the before ' 2019-09-13 23:59:59 ' ; 

note, do not easily go manually delete binlog, will lead to the existence of binlog.index and real binlog do not match, resulting in failure expire_logs_day

 

Guess you like

Origin www.cnblogs.com/linjiqin/p/11520052.html