Rotating MySQL’s binary log closes the current file and starts another. This can help organise replication or recovery logs, but it does not delete old logs or immediately reclaim their disk space.
Check the logging setup
Use an administrator-authorised database account and confirm that binary logging is enabled. Review replication and recovery requirements before making changes.
SHOW VARIABLES LIKE 'log_bin';
SHOW BINARY LOGS;Rotate the current binary log
In a MySQL session with the required RELOAD privilege, run:
FLUSH BINARY LOGS;Alternatively, from the command line:
mysqladmin -u database_admin -p flush-logs binaryReplace the account name and enter the password at the prompt. Review SHOW BINARY LOGS afterwards. Avoid FLUSH LOGS when you only intend to rotate binary logs, because it affects other log types as well.
Purge old logs only when safe
Purging is a separate, permanent deletion operation. First determine the oldest log required by every replica, including disconnected replicas, and by the point-in-time recovery plan. Verify that any required logs are preserved elsewhere.
For a confirmed retention boundary, this example removes logs before the named file while retaining that file:
PURGE BINARY LOGS TO 'mysql-bin.000142';Use a verified filename from your server, not the example unchanged. MySQL 8.4 requires BINLOG_ADMIN for purging. Review the requirements for other versions.
Never delete binary-log files directly from the filesystem. Set an appropriate supported retention policy, such as binlog_expire_logs_seconds, with the administrator instead of relying on repeated manual deletion.