mysql8 close binlog and delete

mysql8 close binlog and delete

Application scenario: Maybe on a single-node service, the disk pressure is too high

edit configuration file

vim /etc/my.cnf
[mysqld]模块中binlog配置的上面,加 skip-log-bin
重启msyql即可关闭binlog

查询Binlog是否开启
show variables like '%log_bin%%';

After the binlog is closed, the previously generated binlog files are not cleared. The disk space is still occupied, and the first thing that comes to mind is to simply delete it directly with rm. Of course, it is no problem to delete directly, but if the order of the binlog files is disturbed, it cannot be executed normally when it is opened later.

The method to delete binlog,

There are two methods, one is automatic deletion and the other is manual deletion. First look at automatic deletion:

Permanent effect: modify the configuration file my.cnf of mysql, add the configuration item of binlog expiration time: expire_logs_days=30, and then restart mysql. This has a fatal disadvantage that it needs to restart mysql.

expire_logs_days=30			数字30是保留30天的意思
或者
binlog_expire_logs_seconds = 2592000 //单位秒

Temporary effect: enter mysql, use the following command to set the global parameters: set global expire_logs_days=30;

You can delete the binlog file directly, but it is safer to delete it through the tools provided by mysql, because purge will update the entries in mysql-bin.index, and if you delete it directly, the mysql-bin.index file will not be updated. The role of mysql-bin.index is to speed up the search for binlog files.

(1) Delete directly

Find the directory where binlog is located, and delete it directly with rm binglog name

Example: rm mysql-bin.010

(2) Delete through the tools provided by mysql

Before deleting, you can take a look at the usage of purge: help purge;

Delete example:

RESET MASTER;			删除所有binlog日志,新日志编号从头开始

PURGE MASTER LOGS TO 'mysql-bin.010';		删除mysql-bin.010之前所有日志

PURGE MASTER LOGS BEFORE '2003-04-02 22:46:26';		 删除2003-04-02 22:46:26之前产生的所有日志

Guess you like

Origin blog.csdn.net/fhw925464207/article/details/131838862