patternsqlMinor
Purge mysql log bins older than two weeks automatically
Viewed 0 times
logthanautomaticallymysqltwopurgeweeksbinsolder
Problem
I have to manually write
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
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
Solution
I am glad you found your own answer.
I am sure you found out you can add this to
You do not have to restart mysql. You login as
To trigger the auto rotate immediately, run
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:
Just apply that query to PURGE BINARY LOGS BEFORE
I am sure you found out you can add this to
my.cnf[mysqld]
expire_logs_days = 14You 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);Code Snippets
[mysqld]
expire_logs_days = 14mysql> SET GLOBAL expire_logs_days = 14;mysql> FLUSH LOGS;SELECT DATE(NOW() - INTERVAL 2 WEEK) + INTERVAL 0 SECOND;PURGE BINARY LOGS BEFORE (DATE(NOW() - INTERVAL 2 WEEK) + INTERVAL 0 SECOND);Context
StackExchange Database Administrators Q#90521, answer score: 6
Revisions (0)
No revisions yet.