dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/mysql/#38
Script #38
mysql
Backupread-onlyMin Version: 5.7

MySQL Binary Log Size and Retention

Shows binary log files, their total size and the retention setting. Important for disk-full prevention and the point-in-time recovery window.

#binlog#disk#retention
mysql · sql
SHOW BINARY LOGS;

SELECT @@log_bin AS log_bin,
       @@binlog_format AS format,
       @@binlog_expire_logs_seconds / 86400 AS retention_days;   -- 8.0+; 5.7 için @@expire_logs_days
Operational Notes & Remediation Guidance

Purge obsolete binary logs safely with `PURGE BINARY LOGS BEFORE NOW() - INTERVAL 7 DAY;`.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 5.7).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.