Pergunta

I have to manually write

purge binary logs bin to "mysql-bin.somenumbers" ;

Once in a while, I need to reduce the spaces that binlogs are taking on my web server. Is it possible to purge binary logs bins automatically every two weeks? probably calling a bash script in crontab?

I have MySQL 5.5 running on CentOS 6.5

Foi útil?

Solução

I am glad you found your own answer.

I am sure you found out you can add this to my.cnf

[mysqld]
expire_logs_days = 14

You do not have to restart mysql. You login as root@localhost and run this:

mysql> SET GLOBAL expire_logs_days = 14;

To trigger the auto rotate immediately, run

mysql> FLUSH LOGS;

If you want to zap binary logs from the mysql console that is older that two weeks, use the PURGE BINARY LOGS BEFORE syntax. For example, here is a query to give you midnight two weeks ago from today's date:

SELECT DATE(NOW() - INTERVAL 2 WEEK) + INTERVAL 0 SECOND;

Just apply that query to PURGE BINARY LOGS BEFORE

PURGE BINARY LOGS BEFORE (DATE(NOW() - INTERVAL 2 WEEK) + INTERVAL 0 SECOND);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a dba.stackexchange
scroll top