How to Check Binlog Retention in MySQL
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
MySQL’s binary log (binlog) is a crucial component for replication and data recovery processes. Understanding and managing the retention of these logs is essential for efficient database administration. This guide explains how to check binlog retention settings in MySQL.
Before diving into the process of checking binlog retention, it’s important to understand what binlog is and why its retention matters. The binlog records all changes to the database, useful for replication and recovery. Retention refers to how long these logs are kept before being purged.
To check binlog retention settings, access your MySQL server:
mysql -u [username] -p
Replace [username] with your MySQL username.
Run the following SQL command in the MySQL shell to view current binlog configurations:
SHOW VARIABLES LIKE 'expire_logs_days';
The expire_logs_days variable indicates the number of days for which the binlogs are retained.
Depending on the MySQL version, you might have different retention settings. In MySQL 8.0+, you can also find the binlog_expire_logs_seconds variable:
SHOW VARIABLES LIKE 'binlog_expire_logs_seconds';
This variable allows for more granular control over log expiration, measured in seconds.
If you need to adjust the binlog retention period, use the SET GLOBAL command. For example, to set retention for 30 days:
SET GLOBAL expire_logs_days = 30;
For second-based configuration in MySQL 8.0+:
SET GLOBAL binlog_expire_logs_seconds = 2592000; -- 30 days in seconds
It’s also important to monitor the size of your binlogs. Use this command to check the disk space used by binlogs:
SHOW MASTER LOGS;
This will list all binlogs and their sizes, helping you understand the storage impact.
Basedash is built as an AI-native BI platform, so teams can go from ad hoc SQL to trusted answers and dashboards quickly, without the overhead of traditional BI setup.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.