HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMajor

MySql - Changing expire_logs_days without restarting the server

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
withouttheexpire_logs_daysmysqlserverchangingrestarting

Problem

I'm using MySql 5.5.
Is it possible to change expire_logs_days and have the changes take effect without restarting the server?

Solution

In MySQL 5.6, you would want to show what your expire_logs_days is set to first. Then confirm that the master doesnt need to keep these logs more than x amount of days. Word of caution, having binary logs that low in days can be a big risk.

Set globally as:

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

mysql> set global expire_logs_days=1;
Query OK, 0 rows affected (0.62 sec)

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

Then dont forget to update the my.cnf file if you want this setting to remain or survive a service restart:

$ sudo vim /etc/my.cnf
expire_logs_days = 1

Then flush the current log and to have the binary log statement to take effect on all the logs older than 1 day, in your case:

mysql> flush binary logs;

Context

StackExchange Database Administrators Q#25841, answer score: 20

Revisions (0)

No revisions yet.