Skip to content

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.

Understanding binlog retention

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.

Accessing MySQL server

To check binlog retention settings, access your MySQL server:

mysql -u [username] -p

Replace [username] with your MySQL username.

Check binlog retention settings

View current binlog configuration

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.

Analyze binlog retention policy

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.

Customize binlog retention

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

Monitor binlog size

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

Robert Cooper avatar

Robert Cooper

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.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.