For the complete documentation index, see llms.txt. This page is also available as Markdown.

Activating the Binary Log

Instructions for enabling the binary log using the --log-bin option and configuring the log file basename and index file.

Turning on Binary Logging

To enable binary logging, start the server with the --log-bin option. Alternatively, add this to the configuration file (for instance, my.cnf), then restart the server:

[client-server]
log_bin

Optionally, you can specify a basename (with or without a path). If you don't, MariaDB assigns a default basename (for instance, c525d37c-b2ff-4543-b06f-87012d142d44-bin), derived from the UUID or hostname of the computer the server runs on. To the basename, file extensions are added, determining the nature of the log files. See this section for details.

From MariaDB 12.3, InnoDB-based binary logs can be used. (This is configurable, and not the default.)

If configured, binary logs are written to InnoDB-managed, page-structured files (with the .ibb extension) that are integrated with InnoDB's redo log and crash recovery, rather than the traditional flat binary log files. This removes the need to protect the binary log separately, since it "inherits" the same crash safety as other InnoDB data, and it removes the need for expensive two-phase commit between InnoDB transactions and the binary log. Some options that apply to traditional binary log files behave differently or no longer apply – for example, sync_binlog is effectively ignored.

InnoDB-based binary logs are enabled by setting binlog_storage_engine=innodb in the server configuration. See InnoDB-Based Binary Log for more information.

On server start, you can set a basename (in the example, with a path) like this:

mariadbd --log-bin=/var/log/mariadb/mariadb-logs

The following applies:

  • If you specify a binary log basename with an extension (for example .log), the extension is silently ignored.

  • If you don't specify a path with the basename, the server logs into datadir . (Datadir is determined by the value of the datadir system variable.)

  • If you don't specify a basename, it is strongly recommended to use --log-basename or to ensure that replication doesn't stop if the hostname of the computer changes.

Verifying Logging is On

Once log-bin or log_bin is configured and the server has been restarted, binary logging is enabled. To verify that, issue this statement:

Viewing Log Files

From MariaDB 12.3, InnoDB-based binary logs can be used. (This is configurable, and not the default.)

If configured, binary logs are written to InnoDB-managed, page-structured files (with the .ibb extension) that are integrated with InnoDB's redo log and crash recovery, rather than the traditional flat binary log files. This removes the need to protect the binary log separately, since it "inherits" the same crash safety as other InnoDB data, and it removes the need for expensive two-phase commit between InnoDB transactions and the binary log. Some options that apply to traditional binary log files behave differently or no longer apply – for example, sync_binlog is effectively ignored.

InnoDB-based binary logs are enabled by setting binlog_storage_engine=innodb in the server configuration. See InnoDB-Based Binary Log for more information.

To view the log files created by the server, issue this statement:

To see which log file is currently used, issue this statement:

To find out where log files are stored, issue this statement:

  • /opt/homebrew/var/mysql/ is the storage location.

  • c525d37c-b2ff-4543-b06f-87012d142d44-bin is the basename of the binary log files.

Log File Organization

From MariaDB 12.3, InnoDB-based binary logs can be used. (This is configurable, and not the default.)

If configured, binary logs are written to InnoDB-managed, page-structured files (with the .ibb extension) that are integrated with InnoDB's redo log and crash recovery, rather than the traditional flat binary log files. This removes the need to protect the binary log separately, since it "inherits" the same crash safety as other InnoDB data, and it removes the need for expensive two-phase commit between InnoDB transactions and the binary log. Some options that apply to traditional binary log files behave differently or no longer apply – for example, sync_binlog is effectively ignored.

InnoDB-based binary logs are enabled by setting binlog_storage_engine=innodb in the server configuration. See InnoDB-Based Binary Log for more information.

Knowing the basename, you can view the log files on the file system, too. Change directory (cd) to the storage location, and issue this command:

  • The binary log index is the file containing an .index extension. It is a plain-text file, containing a master list of the binary log files, in order. By default, the name of the index file is basename.index. This can be overridden with the --log-bin-index option.

  • The binary log files have an extension using consecutive numbers, starting with .000001. (The higher the number, the newer the log file is.)

  • The binary log files for GTID binlog indexing (available from MariaDB 11.4) have an .idx extension.

A new binary log file with a new extension (number) is created:

  • Every time the server starts.

  • When the logs are flushed with a FLUSH LOGS statement.

  • When the maximum size for a binary log file is reached. (This is determined by max_binlog_size.)

Turning off Logging per Session

Clients with the BINLOG ADMIN privilege can disable and re-enable binary logging for the current session by setting the sql_log_bin variable:

Reading Log Files

From MariaDB 12.3, InnoDB-based binary logs can be used. (This is configurable, and not the default.)

If configured, binary logs are written to InnoDB-managed, page-structured files (with the .ibb extension) that are integrated with InnoDB's redo log and crash recovery, rather than the traditional flat binary log files. This removes the need to protect the binary log separately, since it "inherits" the same crash safety as other InnoDB data, and it removes the need for expensive two-phase commit between InnoDB transactions and the binary log. Some options that apply to traditional binary log files behave differently or no longer apply – for example, sync_binlog is effectively ignored.

InnoDB-based binary logs are enabled by setting binlog_storage_engine=innodb in the server configuration. See InnoDB-Based Binary Log for more information.

Log files, with the exception of the index log file, are binary-encoded. To display them in a human-readable format, change directory to the storage location of the log files, and issue this mariadb-binlog command:

To store that output permanently (for instance, for later processing), issue a command like this:

Log File Security

From MariaDB 12.3, InnoDB-based binary logs can be used. (This is configurable, and not the default.)

If configured, binary logs are written to InnoDB-managed, page-structured files (with the .ibb extension) that are integrated with InnoDB's redo log and crash recovery, rather than the traditional flat binary log files. This removes the need to protect the binary log separately, since it "inherits" the same crash safety as other InnoDB data, and it removes the need for expensive two-phase commit between InnoDB transactions and the binary log. Some options that apply to traditional binary log files behave differently or no longer apply – for example, sync_binlog is effectively ignored.

InnoDB-based binary logs are enabled by setting binlog_storage_engine=innodb in the server configuration. See InnoDB-Based Binary Log for more information.

For instructions how to secure binary log files, see Securing MariaDB Logs.

Binary Log Format

There are three formats for the binary log. The default is mixed logging, which is a mix of statement-based and row-based logging. See Binary Log Formats for a detailed discussion.

See Also

This page is licensed: CC BY-SA / Gnu FDL

spinner

Last updated

Was this helpful?