mysql log cleanup

 

Description:

When the mysql database master-slave is enabled, a large number of files such as mysql-bin.00000* log will be generated, which will consume a lot of your hard disk space.

mysql-bin.000001

mysql-bin.000002

mysql-bin.000003

mysql-bin.000004

mysql-bin.000005

 

There are three solutions:

1. Close mysql master and slave, close binlog;

2. Open mysql master and slave, set expire_logs_days;

3. Manually clear the binlog file,> PURGE MASTER LOGS TO'MySQL-bin.010';

 

1. Close mysql master and slave, close binlog

 

# vim /etc/my.cnf // Comment out log-bin, binlog_format

# Replication Master Server (default)

# binary logging is required for replication

# log-bin=mysql-bin

# binary logging format - mixed recommended

# binlog_format=mixed

Then restart the database

 

2. Restart mysql, open mysql master and slave, set expire_logs_days

 

# vim /etc/my.cnf // Modify expire_logs_days, x is the number of days automatically deleted, generally set x to a short point, such as 10

expire_logs_days = x // The number of days that the binary log is automatically deleted. The default value is 0, which means "no automatic deletion"

This method needs to restart mysql, the appendix has an English description about expire_logs_days

Of course, you can also set expire_logs_days directly in mysql without restarting mysql and turning on the mysql master-slave.

> show binary logs;

> show variables like '%log%';

> set global expire_logs_days = 10;

 

3. Manually clear the binlog file

 

Log in to mysql: mysql -u root -p

>  purge master logs before date_sub(current_date, interval 60 day); // Delete MySQL binlog logs 10 days ago, Appendix 2 has usage and examples of manual deletion of PURGE MASTER LOGS

> show master logs;

You can also reset the master and delete all binlog files:

# /usr/local/mysql/bin/mysql -u root -p

> reset master;  // Appendix 3 explains the impact on slave mysql when clearing binlog

 

Guess you like

Origin blog.csdn.net/wangjz2008/article/details/114082145