MySQL Purge Binary Logs: Difference between revisions

From WikiMLT
mNo edit summary
mNo edit summary
 
Line 7: Line 7:
PURGE BINARY LOGS BEFORE '2021-03-07 23:00:00';
PURGE BINARY LOGS BEFORE '2021-03-07 23:00:00';
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="mysql code-continue">
<syntaxhighlight lang="mysql" class="code-continue">
Query OK, 0 rows affected (0.05 sec)
Query OK, 0 rows affected (0.05 sec)
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="mysql" line="1" class="mysql-prompt code-continue">
<syntaxhighlight lang="mysql" line="1" class="mysql-prompt code-continue">exit
mysql> exit
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="mysql code-continue">
<syntaxhighlight lang="mysql" class="code-continue">
Bye
Bye
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 12:32, 12 January 2023

If you are us­ing VPS with lim­it­ed space prob­a­bly it is a good idea to free up some space time to time. One way is by purg­ing the bi­na­ry logs of MySQL. Here are the rel­e­vant com­mands to do that at Ubun­tu 20.04 with MySQL 8 and the de­fault sock­et au­then­ti­ca­tion.

sudo mysql
PURGE BINARY LOGS BEFORE '2021-03-07 23:00:00';
Query OK, 0 rows affected (0.05 sec)
exit
Bye

In ad­di­tion you could mod­i­fy the bin­log ex­pire time as fol­low (restart the MySQL ser­vice af­ter that):

cat /etc/mysql/mysql.conf.d/mysql.binlog.cnf
# SZS: setup binlog expire time - one week in seconds
[mysqld]
binlog_expire_logs_seconds = 604800

Al­so you can re­move the au­to­mysql back­ups old­er than 7 days by the fol­low­ing com­mand.

sudo find /var/lib/automysqlbackup/ -mtime +7 -type f -delete

Ref­er­ences: