TECHIES WORLD

For Techs.... Techniques.... Technologies....

CpanelLinuxMysql

How to configure log rotation for MySQL binlogs

There is not expiration for MySQL binlogs bydefault. This may cause disk space shortage in future. So it will be better to configure log rotation.

MySQL bin log roatation can be done by the following steps.

Step1: Open MySQL config.

#vi /etc/my.cnf

Step2: Update the following parameter under 'mysqld' section and save.

[mysqld]
expire_logs_days=days

Here wee need to replace days with the number of days that we need to keep the logs.

Step3: Restart MySQL.

#service mysqld restart

Please note that the above changes are permanent. If we need to make this temporary (till next service restart), the following query need to run in MySQL terminal.

> SET GLOBAL expire_logs_days = days;

Here wee need to replace days with the number of days that we need to keep the logs.

Also there is one option to remove older binlogs logs manually if needed.

> PURGE BINARY LOGS BEFORE NOW() - INTERVAL 'days' DAY;

Here wee need to replace days with the number of days that we need to keep the logs.

That's all…

Leave a Reply