How to limit binary logs in MariaDB

MariaDb binarny log size is depended on number of days to store on hard drive.

You can change this limit without rebooting server.

See example below how to set limit of 10 days.

First check you are satisfied with date period:

mysql> select date(now()) + interval 0 second - interval 10 day;
+---------------------------------------------------+
| date(now()) + interval 0 second - interval 10 day |
+---------------------------------------------------+
| 2016-12-20 00:00:00 |
+---------------------------------------------------+
1 row in set (0.00 sec)
mysql>


If you want to use more detailed date you can use query:
mysql> select CURRENT_TIMESTAMP - interval 10 day;
+-------------------------------------+
| CURRENT_TIMESTAMP - interval 10 day |
+-------------------------------------+
| 2016-12-20 14:03:21 |
+-------------------------------------+
1 row in set (0.00 sec)
mysql>

Next, log in to mysql and run command

mysql> PURGE BINARY LOGS BEFORE (date(now()) + interval 0 second - interval 10 day);

Thus, the PURGE BINARY LOGS command will delete all binlogs whose datetime stamp predates 2016-12-20 00:00:00.

Finally, run this command

mysql> SET GLOBAL expire_logs_days = 10;

To make this change permanent, set expire_logs_days to be 10 in /etc/my.cnf

[mysqld]
expire_logs_days=10