Page 1 of 1

MySQL log-bin=mysql-bin

Posted: Thu May 12, 2016 1:15 pm
by cah
On my server under /usr/local/var, there are hundreds of mysql-bin.xxxxxx files that take up much disk space. I did some research and found the reason why MySQL creates these files is the configuration in /etc/my.cnf:

Code: Select all

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
The purpose of these binary logs is to replicate from master to slave. Since I don't replicate MySQL, there's no need to have MySQL keep creating these files. I can simply comment out this line in /etc/my.cnf.

Or, if I want to keep these binary logs, I can set up a purge rule in MySQL. There are 2 ways to make it:

1. Purge themmanually from MySQL command line:

Code: Select all

PURGE BINARY LOGS TO 'mysql-bin.000403';
PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';
2. Set the expire_logs_days system variable to expire binary log files automatically after a given number of days.

Code: Select all

mysql> SET GLOBAL expire_logs_days = 7;
Or, set it up in /etc/my.cnf in [mysqld] section

Code: Select all

expire_logs_days = 7
Use the following command to check if the variable is properly set in system.
1. GLOBAL

Code: Select all

mysql> show global variables like 'expire%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 7     |
+------------------+-------+
1 row in set (0.00 sec)
2. SESSION

Code: Select all

mysql> show session variables like 'expire%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 7     |
+------------------+-------+
1 row in set (0.00 sec)