The Binary Logs have two main purposes...
Point in time recovery (PITR)
Replication
SELECT @@log_bin;
SHOW BINARY LOGS;
mysqlbinlog log_file
Binary logging is enabled by default (the log_bin system variable is set to ON).
To enable at startup add this to the startup command...
--log-bin
If you supply the --log-bin option with no string (as shown) or with an empty string, the base name defaults to host_name-bin.To change the base name use: --log-bin[=base_name]If you do not include an absolute path in the base_name definition the binary logs will be written to the data directory.When you enable Binary Logging an index file is also created using the base name with the .index suffix.To disable at startup add this to the startup command...
--skip-log-bin
or
--disable-log-bin
A suitably privileged client can disable binary logging of its own statements using...
SET sql_log_bin=OFF
FLUSH BINARY LOGS;
To delete all existing binary log files and resets the binary log index file...
RESET MASTER
If you do not want the numbering to restart at 1, then use...
RESET MASTER TO 1234
If you just want to remove older logs (without impacting Replication)...
For PITR you need to retain all logs since the start of the last backupPURGE BINARY LOGS TO 'mysql-bin.010';
or
PURGE BINARY LOGS BEFORE '2019-04-02 22:46:26';
Default: OFF
SELECT @@binlog_encryption;
To resize this variable online (without the need to restart MySQL Server)...
SET GLOBAL binlog_encryption=ON;
Default: 2592000
SELECT @@binlog_expire_logs_seconds;
To resize this variable online (without the need to restart MySQL Server)...
SET GLOBAL binlog_expire_logs_seconds=1296000;
Default: ROW
SELECT @@binlog_format;
To resize this variable online (without the need to restart MySQL Server)...
SET GLOBAL binlog_format=ROW;
Default: ON
"Causes the replica to write the updates that are received from a source and performed by the replication SQL thread to the replica's own binary log." (3) Useful when you want to chain replication servers.
SELECT @@log_replica_updates;
Default: OFF (5.7) / ON (8.0)
Useful when you want to chain replication servers
SELECT @@log_slave_updates;
Default: 1073741824 bytes (1 GB)
SELECT @@max_binlog_size;
Default: 1
Recommended: 1
See also: innodb_flush_log_at_trx_commit
SELECT @@sync_binlog;
To change this variable online (without the need to restart MySQL Server)...
SET GLOBAL sync_binlog=0;
0 relies on the OS to flush the binary log to disk from time to time as it does for any other file. This improves performance but risks data loss.Example entries relating to binary logs...
binlog-format = ROW
binlog_expire_logs_seconds = 2592000
expire-logs-days = 0
log-bin = /var/lib/mysql/log
log-replica-updates = ON
sync-binlog = 1
max_binlog_size = 1024M
server-id = 0