All pages
Powered by GitBook
1 of 1

Loading...

Using mariadb-binlog

Previously, the client was called mysqlbinlog. It can still be accessed under this name, via a symlink in Linux, or an alternate binary in Windows.

Overview

The MariaDB server's binary log is a set of files containing "events" which represent modifications to the contents of a MariaDB database.

Events are written in a binary (that is, non-human-readable) format. The mariadb-binlog utility is used to view these events in plain text.

Run from a command line:

See for details on the available options.

Usage

Display the contents of a file named mariadb-bin.000152 like this:

Processing a Single Log File

The logging format is determined by the value of the system variable. If you are using statement-based logging, the output includes the SQL statement, the ID of the server the statement was executed on, a timestamp, and how much time the statement took to execute. If you are using row-based logging, the output of an event will not include an SQL statement, but will instead output how individual rows were changed.

The output from mariadb-binlog can be used as input to the mariadb client to redo the statements contained in a . This is useful for recovering after a server crash (replace binlog-filename with the name of a binary log file):

If you would like to view and possibly edit the file before applying it to your database, use the -r flag to redirect the output to a file (replace outputfile with the name of a file to store the output, and binlog-filename with the name of a binary log file):

In the output file, delete any statements you don't want executed (such as an accidental DROP DATABASE). Once you are satisfied with the contents, you can execute it:

Be careful to process multiple log files in a single connection, especially if one or more of them have any CREATE TEMPORARY TABLE ... statements. Temporary tables are dropped when the mariadb client terminates, so if you are processing multiple log files one at a time (i.e. multiple connections), and one log file creates a temporary table and then a subsequent log file refers to the table, you get an 'unknown table' error.

Processing Multiple Log Files

To execute multiple log files using a single connection, list them all on the mariadb-binlog command line:

If you need to manually edit the binlogs before executing them, combine them all into a single file before processing:

See Also

mariadb-binlog
mariadb-binlog Options
binary log
binlog_format
binary log
mariadb-binlog
mariadb-binlog Options
mariadb-binlog [options] binlog-filename [binlog-filename ...]
mariadb-binlog mariadb-bin.000152
mariadb-binlog binlog-filename | mysql -u root -p
mariadb-binlog -r outputfile binlog-filename
mariadb -u root -p --binary-mode < outputfilename
mariadb-binlog mariadb-bin.000001 mariadb-bin.000002 | mariadb -u root -p --binary-mode
mariadb-binlog mariadb-bin.000001 > /tmp/mariadb-bin.sql
mariadb-binlog mariadb-bin.000002 >> /tmp/mariadb-bin.sql
# make any edits
mariadb -u root -p -e "source /tmp/mariadb-bin.sql"

This page is licensed: GPLv2, originally from fill_help_tables.sql