Introduction MySQL binary logs record all data-modifying operations for replication and point-in-time recovery. When binlogs are not purged—either because `binlog_expire_logs_seconds` is not set, replicas are disconnected, or a sudden burst of writes generates excessive logs—the disk fills up and MySQL stops accepting all write operations.

Symptoms - `ERROR 3 (HY000): Error writing file (Errcode: 28 - No space left on device)` - MySQL logs show `[ERROR] [MY-013145] Disk is full writing binlog` - All INSERT, UPDATE, DELETE operations fail - `SHOW BINARY LOGS` shows many binlog files consuming all disk space - Replicas disconnected due to primary being unable to write new binlog events

Common Causes - `binlog_expire_logs_seconds` not configured (infinite retention) - Replica disconnected for a long time, preventing binlog purge - Bulk load operation generating massive binlog entries - No monitoring on binlog directory size - `max_binlog_size` set too large, creating huge individual files

Step-by-Step Fix 1. **Check current binlog usage": ```sql SHOW BINARY LOGS; SELECT SUM(file_size) AS total_binlog_bytes FROM ( SELECT file_name, file_size FROM mysql.binlog_index ) AS bins;

-- Check expiration setting SHOW VARIABLES LIKE 'binlog_expire_logs_seconds'; SHOW VARIABLES LIKE 'expire_logs_days'; ```

  1. 1.**Emergency: Purge old binlog files":
  2. 2.```sql
  3. 3.-- Purge all binlogs older than a specific date
  4. 4.PURGE BINARY LOGS BEFORE '2026-04-08 00:00:00';

-- Or purge up to a specific log file PURGE BINARY LOGS TO 'binlog.000150';

-- Verify disk space freed SHOW BINARY LOGS; ```

  1. 1.**If replicas are the blocking factor, check their status":
  2. 2.```sql
  3. 3.-- On the primary, check which replicas are connected
  4. 4.SHOW REPLICA HOSTS;

-- On replicas, check their position SHOW REPLICA STATUS\G -- Look for: Relay_Master_Log_File, Exec_Master_Log_Pos ```

  1. 1.**Configure automatic binlog expiration":
  2. 2.```sql
  3. 3.-- MySQL 8.0+
  4. 4.SET GLOBAL binlog_expire_logs_seconds = 259200; -- 3 days

-- Make persistent SET PERSIST binlog_expire_logs_seconds = 259200;

-- In my.cnf -- [mysqld] -- binlog_expire_logs_seconds = 259200 ```

  1. 1.**Free additional disk space if purge is not enough":
  2. 2.```bash
  3. 3.# Check for other large files on the disk
  4. 4.du -sh /var/lib/mysql/* | sort -rh | head -20

# Move old binlogs to another disk temporarily mv /var/lib/mysql/binlog.00000[1-9]* /mnt/backup/binlogs/

# Then purge them from MySQL's perspective PURGE BINARY LOGS TO 'binlog.000010'; ```

Prevention - Set `binlog_expire_logs_seconds` to an appropriate value (3-7 days typical) - Monitor binlog directory size with alerting at 70% capacity - Ensure replicas are always connected and consuming binlogs - Use `binlog_format = ROW` for consistent replication - Size the binlog partition to hold at least 3x the expected daily binlog volume - Set up automated monitoring for replica lag to detect disconnected replicas early - Implement binlog backup to external storage before automatic expiration