MySQL Purge Binary Logs: Difference between revisions
From WikiMLT
mNo edit summary |
mNo edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 4: | Line 4: | ||
sudo mysql | sudo mysql | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="mysql"> | <syntaxhighlight lang="mysql" line="1" class="mysql-prompt code-continue"> | ||
PURGE BINARY LOGS BEFORE '2021-03-07 23:00:00'; | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="mysql" class="code-continue"> | |||
Query OK, 0 rows affected (0.05 sec) | Query OK, 0 rows affected (0.05 sec) | ||
</syntaxhighlight> | |||
mysql> exit | <syntaxhighlight lang="mysql" line="1" class="mysql-prompt code-continue">exit | ||
</syntaxhighlight> | |||
<syntaxhighlight lang="mysql" class="code-continue"> | |||
Bye | Bye | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 11:32, 12 January 2023
If you are using VPS with limited space probably it is a good idea to free up some space time to time. One way is by purging the binary logs of MySQL. Here are the relevant commands to do that at Ubuntu 20.04 with MySQL 8 and the default socket authentication.
sudo mysql
PURGE BINARY LOGS BEFORE '2021-03-07 23:00:00';
Query OK, 0 rows affected (0.05 sec)
exit
Bye
In addition you could modify the binlog expire time as follow (restart the MySQL service after 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
Also you can remove the automysql
backups older than 7 days by the following command.
sudo find /var/lib/automysqlbackup/ -mtime +7 -type f -delete
References:
- MySQL 8.0 Reference Manual: 13.4.1.1 PURGE BINARY LOGS Statement
- Christophe Casalegno: MySQL – how to purge binary logs when you have no space left on device?
- Database Administrators: Is it safe to delete mysql-bin files?
- Mydbops: Binlog expiry now in seconds (MySQL 8.0)