1MYSQLBINLOG(1)               MySQL Database System              MYSQLBINLOG(1)
2
3
4

NAME

6       mysqlbinlog - utility for processing binary log files
7

SYNOPSIS

9       mysqlbinlog [options] log_file ...
10

DESCRIPTION

12       The server's binary log consists of files containing “events” that
13       describe modifications to database contents. The server writes these
14       files in binary format. To display their contents in text format, use
15       the mysqlbinlog utility. You can also use mysqlbinlog to display the
16       contents of relay log files written by a replica server in a
17       replication setup because relay logs have the same format as binary
18       logs. The binary log and relay log are discussed further in
19       Section 5.4.4, “The Binary Log”, and Section 17.2.4, “Relay Log and
20       Replication Metadata Repositories”.
21
22       Invoke mysqlbinlog like this:
23
24           mysqlbinlog [options] log_file ...
25
26       For example, to display the contents of the binary log file named
27       binlog.000003, use this command:
28
29           mysqlbinlog binlog.000003
30
31       The output includes events contained in binlog.000003. For
32       statement-based logging, event information includes the SQL statement,
33       the ID of the server on which it was executed, the timestamp when the
34       statement was executed, how much time it took, and so forth. For
35       row-based logging, the event indicates a row change rather than an SQL
36       statement. See Section 17.2.1, “Replication Formats”, for information
37       about logging modes.
38
39       Events are preceded by header comments that provide additional
40       information. For example:
41
42           # at 141
43           #100309  9:28:36 server id 123  end_log_pos 245
44             Query thread_id=3350  exec_time=11  error_code=0
45
46       In the first line, the number following at indicates the file offset,
47       or starting position, of the event in the binary log file.
48
49       The second line starts with a date and time indicating when the
50       statement started on the server where the event originated. For
51       replication, this timestamp is propagated to replica servers.  server
52       id is the server_id value of the server where the event originated.
53       end_log_pos indicates where the next event starts (that is, it is the
54       end position of the current event + 1).  thread_id indicates which
55       thread executed the event.  exec_time is the time spent executing the
56       event, on a replication source server. On a replica, it is the
57       difference of the end execution time on the replica minus the beginning
58       execution time on the source. The difference serves as an indicator of
59       how much replication lags behind the source.  error_code indicates the
60       result from executing the event. Zero means that no error occurred.
61
62           Note
63           When using event groups, the file offsets of events may be grouped
64           together and the comments of events may be grouped together. Do not
65           mistake these grouped events for blank file offsets.
66
67       The output from mysqlbinlog can be re-executed (for example, by using
68       it as input to mysql) to redo the statements in the log. This is useful
69       for recovery operations after an unexpected server exit. For other
70       usage examples, see the discussion later in this section and in
71       Section 7.5, “Point-in-Time (Incremental) Recovery”. To execute the
72       internal-use BINLOG statements used by mysqlbinlog, the user requires
73       the BINLOG_ADMIN privilege (or the deprecated SUPER privilege), or the
74       REPLICATION_APPLIER privilege plus the appropriate privileges to
75       execute each log event.
76
77       You can use mysqlbinlog to read binary log files directly and apply
78       them to the local MySQL server. You can also read binary logs from a
79       remote server by using the --read-from-remote-server option. To read
80       remote binary logs, the connection parameter options can be given to
81       indicate how to connect to the server. These options are --host,
82       --password, --port, --protocol, --socket, and --user.
83
84       When binary log files have been encrypted, which can be done from MySQL
85       8.0.14 onwards, mysqlbinlog cannot read them directly, but can read
86       them from the server using the --read-from-remote-server option. Binary
87       log files are encrypted when the server's binlog_encryption system
88       variable is set to ON. The SHOW BINARY LOGS statement shows whether a
89       particular binary log file is encrypted or unencrypted. Encrypted and
90       unencrypted binary log files can also be distinguished using the magic
91       number at the start of the file header for encrypted log files
92       (0xFD62696E), which differs from that used for unencrypted log files
93       (0xFE62696E). Note that from MySQL 8.0.14, mysqlbinlog returns a
94       suitable error if you attempt to read an encrypted binary log file
95       directly, but older versions of mysqlbinlog do not recognise the file
96       as a binary log file at all. For more information on binary log
97       encryption, see Section 17.3.2, “Encrypting Binary Log Files and Relay
98       Log Files”.
99
100       When binary log transaction payloads have been compressed, which can be
101       done from MySQL 8.0.20 onwards, mysqlbinlog versions from that release
102       on automatically decompress and decode the transaction payloads, and
103       print them as they would uncompressed events. Older versions of
104       mysqlbinlog cannot read compressed transaction payloads. When the
105       server's binlog_transaction_compression system variable is set to ON,
106       transaction payloads are compressed and then written to the server's
107       binary log file as a single event (a Transaction_payload_event). With
108       the --verbose option, mysqlbinlog adds comments stating the compression
109       algorithm used, the compressed payload size that was originally
110       received, and the resulting payload size after decompression.
111
112           Note
113           The end position (end_log_pos) that mysqlbinlog states for an
114           individual event that was part of a compressed transaction payload
115           is the same as the end position of the original compressed payload.
116           Multiple decompressed events can therefore have the same end
117           position.
118
119           mysqlbinlog's own connection compression does less if transaction
120           payloads are already compressed, but still operates on uncompressed
121           transactions and headers.
122
123       For more information on binary log transaction compression, see
124       Section 5.4.4.5, “Binary Log Transaction Compression”.
125
126       When running mysqlbinlog against a large binary log, be careful that
127       the filesystem has enough space for the resulting files. To configure
128       the directory that mysqlbinlog uses for temporary files, use the TMPDIR
129       environment variable.
130
131       mysqlbinlog sets the value of pseudo_replica_mode or pseudo_slave_mode
132       to true before executing any SQL statements. This system variable
133       affects the handling of XA transactions, the original_commit_timestamp
134       replication delay timestamp and the original_server_version system
135       variable, and unsupported SQL modes.
136
137       mysqlbinlog supports the following options, which can be specified on
138       the command line or in the [mysqlbinlog] and [client] groups of an
139       option file. For information about option files used by MySQL programs,
140       see Section 4.2.2.2, “Using Option Files”.
141
142--help, -?  Display a help message and exit.
143
144--base64-output=value This option determines when events should be
145           displayed encoded as base-64 strings using BINLOG statements. The
146           option has these permissible values (not case-sensitive):
147
148           •   AUTO ("automatic") or UNSPEC ("unspecified") displays BINLOG
149               statements automatically when necessary (that is, for format
150               description events and row events). If no --base64-output
151               option is given, the effect is the same as
152               --base64-output=AUTO.
153
154                   Note
155                   Automatic BINLOG display is the only safe behavior if you
156                   intend to use the output of mysqlbinlog to re-execute
157                   binary log file contents. The other option values are
158                   intended only for debugging or testing purposes because
159                   they may produce output that does not include all events in
160                   executable form.
161
162           •   NEVER causes BINLOG statements not to be displayed.
163               mysqlbinlog exits with an error if a row event is found that
164               must be displayed using BINLOG.
165
166           •   DECODE-ROWS specifies to mysqlbinlog that you intend for row
167               events to be decoded and displayed as commented SQL statements
168               by also specifying the --verbose option. Like NEVER,
169               DECODE-ROWS suppresses display of BINLOG statements, but unlike
170               NEVER, it does not exit with an error if a row event is found.
171
172           For examples that show the effect of --base64-output and --verbose
173           on row event output, see the section called “MYSQLBINLOG ROW EVENT
174           DISPLAY”.
175
176--bind-address=ip_address On a computer having multiple network
177           interfaces, use this option to select which interface to use for
178           connecting to the MySQL server.
179
180--binlog-row-event-max-size=N
181
182           ┌────────────────────┬─────────────────────────┐
183Command-Line Format │ --binlog-row-event-max- │
184           │                    │ size=#                  │
185           ├────────────────────┼─────────────────────────┤
186Type                │ Numeric                 │
187           ├────────────────────┼─────────────────────────┤
188Default Value       │ 4294967040              │
189           ├────────────────────┼─────────────────────────┤
190Minimum Value       │ 256                     │
191           ├────────────────────┼─────────────────────────┤
192Maximum Value       │ 18446744073709547520    │
193           └────────────────────┴─────────────────────────┘
194           Specify the maximum size of a row-based binary log event, in bytes.
195           Rows are grouped into events smaller than this size if possible.
196           The value should be a multiple of 256. The default is 4GB.
197
198--character-sets-dir=dir_name The directory where character sets
199           are installed. See Section 10.15, “Character Set Configuration”.
200
201--compress Compress all information sent between the client and the
202           server if possible. See Section 4.2.8, “Connection Compression
203           Control”.
204
205           This option was added in MySQL 8.0.17. As of MySQL 8.0.18 it is
206           deprecated. Expect it to be removed in a future version of MySQL.
207           See the section called “Configuring Legacy Connection Compression”.
208
209--compression-algorithms=value The permitted compression algorithms
210           for connections to the server. The available algorithms are the
211           same as for the protocol_compression_algorithms system variable.
212           The default value is uncompressed.
213
214           For more information, see Section 4.2.8, “Connection Compression
215           Control”.
216
217           This option was added in MySQL 8.0.18.
218
219--connection-server-id=server_id --connection-server-id specifies
220           the server ID that mysqlbinlog reports when it connects to the
221           server. It can be used to avoid a conflict with the ID of a replica
222           server or another mysqlbinlog process.
223
224           If the --read-from-remote-server option is specified, mysqlbinlog
225           reports a server ID of 0, which tells the server to disconnect
226           after sending the last log file (nonblocking behavior). If the
227           --stop-never option is also specified to maintain the connection to
228           the server, mysqlbinlog reports a server ID of 1 by default instead
229           of 0, and --connection-server-id can be used to replace that server
230           ID if required. See the section called “SPECIFYING THE MYSQLBINLOG
231           SERVER ID”.
232
233--database=db_name, -d db_name This option causes mysqlbinlog to
234           output entries from the binary log (local log only) that occur
235           while db_name is been selected as the default database by USE.
236
237           The --database option for mysqlbinlog is similar to the
238           --binlog-do-db option for mysqld, but can be used to specify only
239           one database. If --database is given multiple times, only the last
240           instance is used.
241
242           The effects of this option depend on whether the statement-based or
243           row-based logging format is in use, in the same way that the
244           effects of --binlog-do-db depend on whether statement-based or
245           row-based logging is in use.
246
247           Statement-based logging. The --database option works as follows:
248
249           •   While db_name is the default database, statements are output
250               whether they modify tables in db_name or a different database.
251
252           •   Unless db_name is selected as the default database, statements
253               are not output, even if they modify tables in db_name.
254
255           •   There is an exception for CREATE DATABASE, ALTER DATABASE, and
256               DROP DATABASE. The database being created, altered, or dropped
257               is considered to be the default database when determining
258               whether to output the statement.
259
260           Suppose that the binary log was created by executing these
261           statements using statement-based-logging:
262
263               INSERT INTO test.t1 (i) VALUES(100);
264               INSERT INTO db2.t2 (j)  VALUES(200);
265               USE test;
266               INSERT INTO test.t1 (i) VALUES(101);
267               INSERT INTO t1 (i)      VALUES(102);
268               INSERT INTO db2.t2 (j)  VALUES(201);
269               USE db2;
270               INSERT INTO test.t1 (i) VALUES(103);
271               INSERT INTO db2.t2 (j)  VALUES(202);
272               INSERT INTO t2 (j)      VALUES(203);
273
274           mysqlbinlog --database=test does not output the first two INSERT
275           statements because there is no default database. It outputs the
276           three INSERT statements following USE test, but not the three
277           INSERT statements following USE db2.
278
279           mysqlbinlog --database=db2 does not output the first two INSERT
280           statements because there is no default database. It does not output
281           the three INSERT statements following USE test, but does output the
282           three INSERT statements following USE db2.
283
284           Row-based logging. mysqlbinlog outputs only entries that change
285           tables belonging to db_name. The default database has no effect on
286           this. Suppose that the binary log just described was created using
287           row-based logging rather than statement-based logging.  mysqlbinlog
288           --database=test outputs only those entries that modify t1 in the
289           test database, regardless of whether USE was issued or what the
290           default database is.  If a server is running with binlog_format set
291           to MIXED and you want it to be possible to use mysqlbinlog with the
292           --database option, you must ensure that tables that are modified
293           are in the database selected by USE. (In particular, no
294           cross-database updates should be used.)
295
296           When used together with the --rewrite-db option, the --rewrite-db
297           option is applied first; then the --database option is applied,
298           using the rewritten database name. The order in which the options
299           are provided makes no difference in this regard.
300
301--debug[=debug_options], -# [debug_options] Write a debugging log.
302           A typical debug_options string is d:t:o,file_name. The default is
303           d:t:o,/tmp/mysqlbinlog.trace.
304
305           This option is available only if MySQL was built using WITH_DEBUG.
306           MySQL release binaries provided by Oracle are not built using this
307           option.
308
309--debug-check Print some debugging information when the program
310           exits.
311
312           This option is available only if MySQL was built using WITH_DEBUG.
313           MySQL release binaries provided by Oracle are not built using this
314           option.
315
316--debug-info Print debugging information and memory and CPU usage
317           statistics when the program exits.
318
319           This option is available only if MySQL was built using WITH_DEBUG.
320           MySQL release binaries provided by Oracle are not built using this
321           option.
322
323--default-auth=plugin A hint about which client-side authentication
324           plugin to use. See Section 6.2.17, “Pluggable Authentication”.
325
326--defaults-extra-file=file_name Read this option file after the
327           global option file but (on Unix) before the user option file. If
328           the file does not exist or is otherwise inaccessible, an error
329           occurs. If file_name is not an absolute path name, it is
330           interpreted relative to the current directory.
331
332           For additional information about this and other option-file
333           options, see Section 4.2.2.3, “Command-Line Options that Affect
334           Option-File Handling”.
335
336--defaults-file=file_name Use only the given option file. If the
337           file does not exist or is otherwise inaccessible, an error occurs.
338           If file_name is not an absolute path name, it is interpreted
339           relative to the current directory.
340
341           Exception: Even with --defaults-file, client programs read
342           .mylogin.cnf.
343
344           For additional information about this and other option-file
345           options, see Section 4.2.2.3, “Command-Line Options that Affect
346           Option-File Handling”.
347
348--defaults-group-suffix=str Read not only the usual option groups,
349           but also groups with the usual names and a suffix of str. For
350           example, mysqlbinlog normally reads the [client] and [mysqlbinlog]
351           groups. If this option is given as --defaults-group-suffix=_other,
352           mysqlbinlog also reads the [client_other] and [mysqlbinlog_other]
353           groups.
354
355           For additional information about this and other option-file
356           options, see Section 4.2.2.3, “Command-Line Options that Affect
357           Option-File Handling”.
358
359--disable-log-bin, -D Disable binary logging. This is useful for
360           avoiding an endless loop if you use the --to-last-log option and
361           are sending the output to the same MySQL server. This option also
362           is useful when restoring after an unexpected exit to avoid
363           duplication of the statements you have logged.
364
365           This option causes mysqlbinlog to include a SET sql_log_bin = 0
366           statement in its output to disable binary logging of the remaining
367           output. Manipulating the session value of the sql_log_bin system
368           variable is a restricted operation, so this option requires that
369           you have privileges sufficient to set restricted session variables.
370           See Section 5.1.9.1, “System Variable Privileges”.
371
372--exclude-gtids=gtid_set Do not display any of the groups listed in
373           the gtid_set.
374
375--force-if-open, -F Read binary log files even if they are open or
376           were not closed properly (IN_USE flag is set); do not fail if the
377           file ends with a truncated event.
378
379           The IN_USE flag is set only for the binary log that is currently
380           written by the server; if the server has crashed, the flag remains
381           set until the server is started up again and recovers the binary
382           log. Without this option, mysqlbinlog refuses to process a file
383           with this flag set. Since the server may be in the process of
384           writing the file, truncation of the last event is considered
385           normal.
386
387--force-read, -f With this option, if mysqlbinlog reads a binary
388           log event that it does not recognize, it prints a warning, ignores
389           the event, and continues. Without this option, mysqlbinlog stops if
390           it reads such an event.
391
392--get-server-public-key Request from the server the public key
393           required for RSA key pair-based password exchange. This option
394           applies to clients that authenticate with the caching_sha2_password
395           authentication plugin. For that plugin, the server does not send
396           the public key unless requested. This option is ignored for
397           accounts that do not authenticate with that plugin. It is also
398           ignored if RSA-based password exchange is not used, as is the case
399           when the client connects to the server using a secure connection.
400
401           If --server-public-key-path=file_name is given and specifies a
402           valid public key file, it takes precedence over
403           --get-server-public-key.
404
405           For information about the caching_sha2_password plugin, see
406           Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.
407
408--hexdump, -H Display a hex dump of the log in comments, as
409           described in the section called “MYSQLBINLOG HEX DUMP FORMAT”. The
410           hex output can be helpful for replication debugging.
411
412--host=host_name, -h host_name Get the binary log from the MySQL
413           server on the given host.
414
415--idempotent Tell the MySQL Server to use idempotent mode while
416           processing updates; this causes suppression of any duplicate-key or
417           key-not-found errors that the server encounters in the current
418           session while processing updates. This option may prove useful
419           whenever it is desirable or necessary to replay one or more binary
420           logs to a MySQL Server which may not contain all of the data to
421           which the logs refer.
422
423           The scope of effect for this option includes the current
424           mysqlbinlog client and session only.
425
426--include-gtids=gtid_set Display only the groups listed in the
427           gtid_set.
428
429--local-load=dir_name, -l dir_name For data loading operations
430           corresponding to LOAD DATA statements, mysqlbinlog extracts the
431           files from the binary log events, writes them as temporary files to
432           the local file system, and writes LOAD DATA LOCAL statements to
433           cause the files to be loaded. By default, mysqlbinlog writes these
434           temporary files to an operating system-specific directory. The
435           --local-load option can be used to explicitly specify the directory
436           where mysqlbinlog should prepare local temporary files.
437
438           Because other processes can write files to the default
439           system-specific directory, it is advisable to specify the
440           --local-load option to mysqlbinlog to designate a different
441           directory for data files, and then designate that same directory by
442           specifying the --load-data-local-dir option to mysql when
443           processing the output from mysqlbinlog. For example:
444
445               mysqlbinlog --local-load=/my/local/data ...
446                   | mysql --load-data-local-dir=/my/local/data ...
447
448               Important
449               These temporary files are not automatically removed by
450               mysqlbinlog or any other MySQL program.
451
452--login-path=name Read options from the named login path in the
453           .mylogin.cnf login path file. A “login path” is an option group
454           containing options that specify which MySQL server to connect to
455           and which account to authenticate as. To create or modify a login
456           path file, use the mysql_config_editor utility. See
457           mysql_config_editor(1).
458
459           For additional information about this and other option-file
460           options, see Section 4.2.2.3, “Command-Line Options that Affect
461           Option-File Handling”.
462
463--no-defaults Do not read any option files. If program startup
464           fails due to reading unknown options from an option file,
465           --no-defaults can be used to prevent them from being read.
466
467           The exception is that the .mylogin.cnf file is read in all cases,
468           if it exists. This permits passwords to be specified in a safer way
469           than on the command line even when --no-defaults is used. To create
470           .mylogin.cnf, use the mysql_config_editor utility. See
471           mysql_config_editor(1).
472
473           For additional information about this and other option-file
474           options, see Section 4.2.2.3, “Command-Line Options that Affect
475           Option-File Handling”.
476
477--offset=N, -o N Skip the first N entries in the log.
478
479--open-files-limit=N Specify the number of open file descriptors to
480           reserve.
481
482--password[=password], -p[password] The password of the MySQL
483           account used for connecting to the server. The password value is
484           optional. If not given, mysqlbinlog prompts for one. If given,
485           there must be no space between --password= or -p and the password
486           following it. If no password option is specified, the default is to
487           send no password.
488
489           Specifying a password on the command line should be considered
490           insecure. To avoid giving the password on the command line, use an
491           option file. See Section 6.1.2.1, “End-User Guidelines for Password
492           Security”.
493
494           To explicitly specify that there is no password and that
495           mysqlbinlog should not prompt for one, use the --skip-password
496           option.
497
498--plugin-dir=dir_name The directory in which to look for plugins.
499           Specify this option if the --default-auth option is used to specify
500           an authentication plugin but mysqlbinlog does not find it. See
501           Section 6.2.17, “Pluggable Authentication”.
502
503--port=port_num, -P port_num The TCP/IP port number to use for
504           connecting to a remote server.
505
506--print-defaults Print the program name and all options that it
507           gets from option files.
508
509           For additional information about this and other option-file
510           options, see Section 4.2.2.3, “Command-Line Options that Affect
511           Option-File Handling”.
512
513--print-table-metadata Print table related metadata from the binary
514           log. Configure the amount of table related metadata binary logged
515           using binlog-row-metadata.
516
517--protocol={TCP|SOCKET|PIPE|MEMORY} The transport protocol to use
518           for connecting to the server. It is useful when the other
519           connection parameters normally result in use of a protocol other
520           than the one you want. For details on the permissible values, see
521           Section 4.2.7, “Connection Transport Protocols”.
522
523--raw By default, mysqlbinlog reads binary log files and writes
524           events in text format. The --raw option tells mysqlbinlog to write
525           them in their original binary format. Its use requires that
526           --read-from-remote-server also be used because the files are
527           requested from a server.  mysqlbinlog writes one output file for
528           each file read from the server. The --raw option can be used to
529           make a backup of a server's binary log. With the --stop-never
530           option, the backup is “live” because mysqlbinlog stays connected to
531           the server. By default, output files are written in the current
532           directory with the same names as the original log files. Output
533           file names can be modified using the --result-file option. For more
534           information, see the section called “USING MYSQLBINLOG TO BACK UP
535           BINARY LOG FILES”.
536
537--read-from-remote-source=type From MySQL 8.0.26, use
538           --read-from-remote-source, and before MySQL 8.0.26, use
539           --read-from-remote-master. Both options have the same effect. The
540           options read binary logs from a MySQL server with the
541           COM_BINLOG_DUMP or COM_BINLOG_DUMP_GTID commands by setting the
542           option value to either BINLOG-DUMP-NON-GTIDS or BINLOG-DUMP-GTIDS,
543           respectively. If --read-from-remote-source=BINLOG-DUMP-GTIDS or
544           --read-from-remote-master=BINLOG-DUMP-GTIDS is combined with
545           --exclude-gtids, transactions can be filtered out on the source,
546           avoiding unnecessary network traffic.
547
548           The connection parameter options are used with these options or the
549           --read-from-remote-server option. These options are --host,
550           --password, --port, --protocol, --socket, and --user. If none of
551           the remote options is specified, the connection parameter options
552           are ignored.
553
554           The REPLICATION SLAVE privilege is required to use these options.
555
556--read-from-remote-master=type Use this option before MySQL 8.0.26
557           rather than --read-from-remote-source. Both options have the same
558           effect.
559
560--read-from-remote-server=file_name, -R Read the binary log from a
561           MySQL server rather than reading a local log file. This option
562           requires that the remote server be running. It works only for
563           binary log files on the remote server, not relay log files, and
564           takes only the binary log file name (including the numeric suffix)
565           as its argument, while ignoring any path.
566
567           The connection parameter options are used with this option or the
568           --read-from-remote-master option. These options are --host,
569           --password, --port, --protocol, --socket, and --user. If neither of
570           the remote options is specified, the connection parameter options
571           are ignored.
572
573           The REPLICATION SLAVE privilege is required to use this option.
574
575           This option is like
576           --read-from-remote-master=BINLOG-DUMP-NON-GTIDS.
577
578--result-file=name, -r name Without the --raw option, this option
579           indicates the file to which mysqlbinlog writes text output. With
580           --raw, mysqlbinlog writes one binary output file for each log file
581           transferred from the server, writing them by default in the current
582           directory using the same names as the original log file. In this
583           case, the --result-file option value is treated as a prefix that
584           modifies output file names.
585
586--require-row-format Require row-based binary logging format for
587           events. This option enforces row-based replication events for
588           mysqlbinlog output. The stream of events produced with this option
589           would be accepted by a replication channel that is secured using
590           the REQUIRE_ROW_FORMAT option of the CHANGE REPLICATION SOURCE TO
591           statement (from MySQL 8.0.23) or CHANGE MASTER TO statement (before
592           MySQL 8.0.23).  binlog_format=ROW must be set on the server where
593           the binary log was written. When you specify this option,
594           mysqlbinlog stops with an error message if it encounters any events
595           that are disallowed under the REQUIRE_ROW_FORMAT restrictions,
596           including LOAD DATA INFILE instructions, creating or dropping
597           temporary tables, INTVAR, RAND, or USER_VAR events, and
598           non-row-based events within a DML transaction.  mysqlbinlog also
599           prints a SET @@session.require_row_format statement at the start of
600           its output to apply the restrictions when the output is executed,
601           and does not print the SET @@session.pseudo_thread_id statement.
602
603           This option was added in MySQL 8.0.19.
604
605--rewrite-db='from_name->to_name' When reading from a row-based or
606           statement-based log, rewrite all occurrences of from_name to
607           to_name. Rewriting is done on the rows, for row-based logs, as well
608           as on the USE clauses, for statement-based logs.
609
610               Warning
611               Statements in which table names are qualified with database
612               names are not rewritten to use the new name when using this
613               option.
614           The rewrite rule employed as a value for this option is a string
615           having the form 'from_name->to_name', as shown previously, and for
616           this reason must be enclosed by quotation marks.
617
618           To employ multiple rewrite rules, specify the option multiple
619           times, as shown here:
620
621               mysqlbinlog --rewrite-db='dbcurrent->dbold' --rewrite-db='dbtest->dbcurrent' \
622                   binlog.00001 > /tmp/statements.sql
623
624           When used together with the --database option, the --rewrite-db
625           option is applied first; then --database option is applied, using
626           the rewritten database name. The order in which the options are
627           provided makes no difference in this regard.
628
629           This means that, for example, if mysqlbinlog is started with
630           --rewrite-db='mydb->yourdb' --database=yourdb, then all updates to
631           any tables in databases mydb and yourdb are included in the output.
632           On the other hand, if it is started with
633           --rewrite-db='mydb->yourdb' --database=mydb, then mysqlbinlog
634           outputs no statements at all: since all updates to mydb are first
635           rewritten as updates to yourdb before applying the --database
636           option, there remain no updates that match --database=mydb.
637
638--server-id=id Display only those events created by the server
639           having the given server ID.
640
641--server-id-bits=N Use only the first N bits of the server_id to
642           identify the server. If the binary log was written by a mysqld with
643           server-id-bits set to less than 32 and user data stored in the most
644           significant bit, running mysqlbinlog with --server-id-bits set to
645           32 enables this data to be seen.
646
647           This option is supported only by the version of mysqlbinlog
648           supplied with the NDB Cluster distribution, or built with NDB
649           Cluster support.
650
651--server-public-key-path=file_name The path name to a file in PEM
652           format containing a client-side copy of the public key required by
653           the server for RSA key pair-based password exchange. This option
654           applies to clients that authenticate with the sha256_password or
655           caching_sha2_password authentication plugin. This option is ignored
656           for accounts that do not authenticate with one of those plugins. It
657           is also ignored if RSA-based password exchange is not used, as is
658           the case when the client connects to the server using a secure
659           connection.
660
661           If --server-public-key-path=file_name is given and specifies a
662           valid public key file, it takes precedence over
663           --get-server-public-key.
664
665           For sha256_password, this option applies only if MySQL was built
666           using OpenSSL.
667
668           For information about the sha256_password and caching_sha2_password
669           plugins, see Section 6.4.1.3, “SHA-256 Pluggable Authentication”,
670           and Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.
671
672--set-charset=charset_name Add a SET NAMES charset_name statement
673           to the output to specify the character set to be used for
674           processing log files.
675
676--shared-memory-base-name=name On Windows, the shared-memory name
677           to use for connections made using shared memory to a local server.
678           The default value is MYSQL. The shared-memory name is
679           case-sensitive.
680
681           This option applies only if the server was started with the
682           shared_memory system variable enabled to support shared-memory
683           connections.
684
685--short-form, -s Display only the statements contained in the log,
686           without any extra information or row-based events. This is for
687           testing only, and should not be used in production systems. It is
688           deprecated, and you should expect it to be removed in a future
689           release.
690
691--skip-gtids[=(true|false)] Do not include the GTIDs from the
692           binary log files in the output dump file. For example:
693
694               mysqlbinlog --skip-gtids binlog.000001 >  /tmp/dump.sql
695               mysql -u root -p -e "source /tmp/dump.sql"
696
697           You should not normally use this option in production or in
698           recovery, except in the specific, and rare, scenarios where the
699           GTIDs are actively unwanted. For example, an administrator might
700           want to duplicate selected transactions (such as table definitions)
701           from a deployment to another, unrelated, deployment that will not
702           replicate to or from the original. In that scenario, --skip-gtids
703           can be used to enable the administrator to apply the transactions
704           as if they were new, and ensure that the deployments remain
705           unrelated. However, you should only use this option if the
706           inclusion of the GTIDs causes a known issue for your use case.
707
708--socket=path, -S path For connections to localhost, the Unix
709           socket file to use, or, on Windows, the name of the named pipe to
710           use.
711
712           On Windows, this option applies only if the server was started with
713           the named_pipe system variable enabled to support named-pipe
714           connections. In addition, the user making the connection must be a
715           member of the Windows group specified by the
716           named_pipe_full_access_group system variable.
717
718--ssl* Options that begin with --ssl specify whether to connect to
719           the server using encryption and indicate where to find SSL keys and
720           certificates. See the section called “Command Options for Encrypted
721           Connections”.
722
723--ssl-fips-mode={OFF|ON|STRICT} Controls whether to enable FIPS
724           mode on the client side. The --ssl-fips-mode option differs from
725           other --ssl-xxx options in that it is not used to establish
726           encrypted connections, but rather to affect which cryptographic
727           operations to permit. See Section 6.8, “FIPS Support”.
728
729           These --ssl-fips-mode values are permitted:
730
731           •   OFF: Disable FIPS mode.
732
733           •   ON: Enable FIPS mode.
734
735           •   STRICT: Enable “strict” FIPS mode.
736
737
738               Note
739               If the OpenSSL FIPS Object Module is not available, the only
740               permitted value for --ssl-fips-mode is OFF. In this case,
741               setting --ssl-fips-mode to ON or STRICT causes the client to
742               produce a warning at startup and to operate in non-FIPS mode.
743           As of MySQL 8.0.34, this option is deprecated. Expect it to be
744           removed in a future version of MySQL.
745
746--start-datetime=datetime Start reading the binary log at the first
747           event having a timestamp equal to or later than the datetime
748           argument. The datetime value is relative to the local time zone on
749           the machine where you run mysqlbinlog. The value should be in a
750           format accepted for the DATETIME or TIMESTAMP data types. For
751           example:
752
753               mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000003
754
755           This option is useful for point-in-time recovery. See Section 7.5,
756           “Point-in-Time (Incremental) Recovery”.
757
758--start-position=N, -j N Start decoding the binary log at the log
759           position N, including in the output any events that begin at
760           position N or after. The position is a byte point in the log file,
761           not an event counter; it needs to point to the starting position of
762           an event to generate useful output. This option applies to the
763           first log file named on the command line.
764
765           Prior to MySQL 8.0.33, the maximum value supported for this option
766           was 4294967295 (232-1). In MySQL 8.0.33 and later, it is
767           18446744073709551616 (264-1), unless --read-from-remote-server or
768           --read-from-remote-source is also used, in which case the maximum
769           is 4294967295.
770
771           This option is useful for point-in-time recovery. See Section 7.5,
772           “Point-in-Time (Incremental) Recovery”.
773
774--stop-datetime=datetime Stop reading the binary log at the first
775           event having a timestamp equal to or later than the datetime
776           argument. See the description of the --start-datetime option for
777           information about the datetime value.
778
779           This option is useful for point-in-time recovery. See Section 7.5,
780           “Point-in-Time (Incremental) Recovery”.
781
782--stop-never This option is used with --read-from-remote-server. It
783           tells mysqlbinlog to remain connected to the server. Otherwise
784           mysqlbinlog exits when the last log file has been transferred from
785           the server.  --stop-never implies --to-last-log, so only the first
786           log file to transfer need be named on the command line.
787
788           --stop-never is commonly used with --raw to make a live binary log
789           backup, but also can be used without --raw to maintain a continuous
790           text display of log events as the server generates them.
791
792           With --stop-never, by default, mysqlbinlog reports a server ID of 1
793           when it connects to the server. Use --connection-server-id to
794           explicitly specify an alternative ID to report. It can be used to
795           avoid a conflict with the ID of a replica server or another
796           mysqlbinlog process. See the section called “SPECIFYING THE
797           MYSQLBINLOG SERVER ID”.
798
799--stop-never-slave-server-id=id This option is deprecated; expect
800           it to be removed in a future release. Use the
801           --connection-server-id option instead to specify a server ID for
802           mysqlbinlog to report.
803
804--stop-position=N Stop decoding the binary log at the log position
805           N, excluding from the output any events that begin at position N or
806           after. The position is a byte point in the log file, not an event
807           counter; it needs to point to a spot after the starting position of
808           the last event you want to include in the output. The event
809           starting before position N and finishing at or after the position
810           is the last event to be processed. This option applies to the last
811           log file named on the command line.
812
813           This option is useful for point-in-time recovery. See Section 7.5,
814           “Point-in-Time (Incremental) Recovery”.
815
816--tls-ciphersuites=ciphersuite_list The permissible ciphersuites
817           for encrypted connections that use TLSv1.3. The value is a list of
818           one or more colon-separated ciphersuite names. The ciphersuites
819           that can be named for this option depend on the SSL library used to
820           compile MySQL. For details, see Section 6.3.2, “Encrypted
821           Connection TLS Protocols and Ciphers”.
822
823           This option was added in MySQL 8.0.16.
824
825--tls-version=protocol_list The permissible TLS protocols for
826           encrypted connections. The value is a list of one or more
827           comma-separated protocol names. The protocols that can be named for
828           this option depend on the SSL library used to compile MySQL. For
829           details, see Section 6.3.2, “Encrypted Connection TLS Protocols and
830           Ciphers”.
831
832--to-last-log, -t Do not stop at the end of the requested binary
833           log from a MySQL server, but rather continue printing until the end
834           of the last binary log. If you send the output to the same MySQL
835           server, this may lead to an endless loop. This option requires
836           --read-from-remote-server.
837
838--user=user_name, -u user_name The user name of the MySQL account
839           to use when connecting to a remote server.
840
841           If you are using the Rewriter plugin with MySQL 8.0.31 or later,
842           you should grant this user the SKIP_QUERY_REWRITE privilege.
843
844--verbose, -v Reconstruct row events and display them as commented
845           SQL statements, with table partition information where applicable.
846           If this option is given twice (by passing in either "-vv" or
847           "--verbose --verbose"), the output includes comments to indicate
848           column data types and some metadata, and informational log events
849           such as row query log events if the binlog_rows_query_log_events
850           system variable is set to TRUE.
851
852           For examples that show the effect of --base64-output and --verbose
853           on row event output, see the section called “MYSQLBINLOG ROW EVENT
854           DISPLAY”.
855
856--verify-binlog-checksum, -c Verify checksums in binary log files.
857
858--version, -V Display version information and exit.
859
860           The mysqlbinlog version number shown when using this option is 3.4.
861
862--zstd-compression-level=level The compression level to use for
863           connections to the server that use the zstd compression algorithm.
864           The permitted levels are from 1 to 22, with larger values
865           indicating increasing levels of compression. The default zstd
866           compression level is 3. The compression level setting has no effect
867           on connections that do not use zstd compression.
868
869           For more information, see Section 4.2.8, “Connection Compression
870           Control”.
871
872           This option was added in MySQL 8.0.18.
873
874       You can pipe the output of mysqlbinlog into the mysql client to execute
875       the events contained in the binary log. This technique is used to
876       recover from an unexpected exit when you have an old backup (see
877       Section 7.5, “Point-in-Time (Incremental) Recovery”). For example:
878
879           mysqlbinlog binlog.000001 | mysql -u root -p
880
881       Or:
882
883           mysqlbinlog binlog.[0-9]* | mysql -u root -p
884
885       If the statements produced by mysqlbinlog may contain BLOB values,
886       these may cause problems when mysql processes them. In this case,
887       invoke mysql with the --binary-mode option.
888
889       You can also redirect the output of mysqlbinlog to a text file instead,
890       if you need to modify the statement log first (for example, to remove
891       statements that you do not want to execute for some reason). After
892       editing the file, execute the statements that it contains by using it
893       as input to the mysql program:
894
895           mysqlbinlog binlog.000001 > tmpfile
896           ... edit tmpfile ...
897           mysql -u root -p < tmpfile
898
899       When mysqlbinlog is invoked with the --start-position option, it
900       displays only those events with an offset in the binary log greater
901       than or equal to a given position (the given position must match the
902       start of one event). It also has options to stop and start when it sees
903       an event with a given date and time. This enables you to perform
904       point-in-time recovery using the --stop-datetime option (to be able to
905       say, for example, “roll forward my databases to how they were today at
906       10:30 a.m.”).
907
908       Processing multiple files. If you have more than one binary log to
909       execute on the MySQL server, the safe method is to process them all
910       using a single connection to the server. Here is an example that
911       demonstrates what may be unsafe:
912
913           mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
914           mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!
915
916       Processing binary logs this way using multiple connections to the
917       server causes problems if the first log file contains a CREATE
918       TEMPORARY TABLE statement and the second log contains a statement that
919       uses the temporary table. When the first mysql process terminates, the
920       server drops the temporary table. When the second mysql process
921       attempts to use the table, the server reports “unknown table.”
922
923       To avoid problems like this, use a single mysql process to execute the
924       contents of all binary logs that you want to process. Here is one way
925       to do so:
926
927           mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
928
929       Another approach is to write all the logs to a single file and then
930       process the file:
931
932           mysqlbinlog binlog.000001 >  /tmp/statements.sql
933           mysqlbinlog binlog.000002 >> /tmp/statements.sql
934           mysql -u root -p -e "source /tmp/statements.sql"
935
936       From MySQL 8.0.12, you can also supply multiple binary log files to
937       mysqlbinlog as streamed input using a shell pipe. An archive of
938       compressed binary log files can be decompressed and provided directly
939       to mysqlbinlog. In this example, binlog-files_1.gz contains multiple
940       binary log files for processing. The pipeline extracts the contents of
941       binlog-files_1.gz, pipes the binary log files to mysqlbinlog as
942       standard input, and pipes the output of mysqlbinlog into the mysql
943       client for execution:
944
945           gzip -cd binlog-files_1.gz | ./mysqlbinlog - | ./mysql -uroot  -p
946
947       You can specify more than one archive file, for example:
948
949           gzip -cd binlog-files_1.gz binlog-files_2.gz | ./mysqlbinlog - | ./mysql -uroot  -p
950
951       For streamed input, do not use --stop-position, because mysqlbinlog
952       cannot identify the last log file to apply this option.
953
954       LOAD DATA operations. mysqlbinlog can produce output that reproduces a
955       LOAD DATA operation without the original data file.  mysqlbinlog copies
956       the data to a temporary file and writes a LOAD DATA LOCAL statement
957       that refers to the file. The default location of the directory where
958       these files are written is system-specific. To specify a directory
959       explicitly, use the --local-load option.
960
961       Because mysqlbinlog converts LOAD DATA statements to LOAD DATA LOCAL
962       statements (that is, it adds LOCAL), both the client and the server
963       that you use to process the statements must be configured with the
964       LOCAL capability enabled. See Section 6.1.6, “Security Considerations
965       for LOAD DATA LOCAL”.
966
967           Warning
968           The temporary files created for LOAD DATA LOCAL statements are not
969           automatically deleted because they are needed until you actually
970           execute those statements. You should delete the temporary files
971           yourself after you no longer need the statement log. The files can
972           be found in the temporary file directory and have names like
973           original_file_name-#-#.
974

MYSQLBINLOG HEX DUMP FORMAT

976       The --hexdump option causes mysqlbinlog to produce a hex dump of the
977       binary log contents:
978
979           mysqlbinlog --hexdump source-bin.000001
980
981       The hex output consists of comment lines beginning with #, so the
982       output might look like this for the preceding command:
983
984           /*!40019 SET @@SESSION.max_insert_delayed_threads=0*/;
985           /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
986           # at 4
987           #051024 17:24:13 server id 1  end_log_pos 98
988           # Position  Timestamp   Type   Master ID        Size      Master Pos    Flags
989           # 00000004 9d fc 5c 43   0f   01 00 00 00   5e 00 00 00   62 00 00 00   00 00
990           # 00000017 04 00 35 2e 30 2e 31 35  2d 64 65 62 75 67 2d 6c |..5.0.15.debug.l|
991           # 00000027 6f 67 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |og..............|
992           # 00000037 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |................|
993           # 00000047 00 00 00 00 9d fc 5c 43  13 38 0d 00 08 00 12 00 |.......C.8......|
994           # 00000057 04 04 04 04 12 00 00 4b  00 04 1a                |.......K...|
995           #       Start: binlog v 4, server v 5.0.15-debug-log created 051024 17:24:13
996           #       at startup
997           ROLLBACK;
998
999       Hex dump output currently contains the elements in the following list.
1000       This format is subject to change. For more information about binary log
1001       format, see MySQL Internals: The Binary Log[1].
1002
1003       •   Position: The byte position within the log file.
1004
1005       •   Timestamp: The event timestamp. In the example shown, '9d fc 5c 43'
1006           is the representation of '051024 17:24:13' in hexadecimal.
1007
1008       •   Type: The event type code.
1009
1010       •   Master ID: The server ID of the replication source server that
1011           created the event.
1012
1013       •   Size: The size in bytes of the event.
1014
1015       •   Master Pos: The position of the next event in the original source's
1016           binary log file.
1017
1018       •   Flags: Event flag values.
1019

MYSQLBINLOG ROW EVENT DISPLAY

1021       The following examples illustrate how mysqlbinlog displays row events
1022       that specify data modifications. These correspond to events with the
1023       WRITE_ROWS_EVENT, UPDATE_ROWS_EVENT, and DELETE_ROWS_EVENT type codes.
1024       The --base64-output=DECODE-ROWS and --verbose options may be used to
1025       affect row event output.
1026
1027       Suppose that the server is using row-based binary logging and that you
1028       execute the following sequence of statements:
1029
1030           CREATE TABLE t
1031           (
1032             id   INT NOT NULL,
1033             name VARCHAR(20) NOT NULL,
1034             date DATE NULL
1035           ) ENGINE = InnoDB;
1036           START TRANSACTION;
1037           INSERT INTO t VALUES(1, 'apple', NULL);
1038           UPDATE t SET name = 'pear', date = '2009-01-01' WHERE id = 1;
1039           DELETE FROM t WHERE id = 1;
1040           COMMIT;
1041
1042       By default, mysqlbinlog displays row events encoded as base-64 strings
1043       using BINLOG statements. Omitting extraneous lines, the output for the
1044       row events produced by the preceding statement sequence looks like
1045       this:
1046
1047           $> mysqlbinlog log_file
1048           ...
1049           # at 218
1050           #080828 15:03:08 server id 1  end_log_pos 258   Write_rows: table id 17 flags: STMT_END_F
1051           BINLOG '
1052           fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1053           fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
1054           '/*!*/;
1055           ...
1056           # at 302
1057           #080828 15:03:08 server id 1  end_log_pos 356   Update_rows: table id 17 flags: STMT_END_F
1058           BINLOG '
1059           fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1060           fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
1061           '/*!*/;
1062           ...
1063           # at 400
1064           #080828 15:03:08 server id 1  end_log_pos 442   Delete_rows: table id 17 flags: STMT_END_F
1065           BINLOG '
1066           fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1067           fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
1068           '/*!*/;
1069
1070       To see the row events as comments in the form of “pseudo-SQL”
1071       statements, run mysqlbinlog with the --verbose or -v option. This
1072       output level also shows table partition information where applicable.
1073       The output contains lines beginning with ###:
1074
1075           $> mysqlbinlog -v log_file
1076           ...
1077           # at 218
1078           #080828 15:03:08 server id 1  end_log_pos 258   Write_rows: table id 17 flags: STMT_END_F
1079           BINLOG '
1080           fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1081           fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
1082           '/*!*/;
1083           ### INSERT INTO test.t
1084           ### SET
1085           ###   @1=1
1086           ###   @2='apple'
1087           ###   @3=NULL
1088           ...
1089           # at 302
1090           #080828 15:03:08 server id 1  end_log_pos 356   Update_rows: table id 17 flags: STMT_END_F
1091           BINLOG '
1092           fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1093           fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
1094           '/*!*/;
1095           ### UPDATE test.t
1096           ### WHERE
1097           ###   @1=1
1098           ###   @2='apple'
1099           ###   @3=NULL
1100           ### SET
1101           ###   @1=1
1102           ###   @2='pear'
1103           ###   @3='2009:01:01'
1104           ...
1105           # at 400
1106           #080828 15:03:08 server id 1  end_log_pos 442   Delete_rows: table id 17 flags: STMT_END_F
1107           BINLOG '
1108           fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1109           fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
1110           '/*!*/;
1111           ### DELETE FROM test.t
1112           ### WHERE
1113           ###   @1=1
1114           ###   @2='pear'
1115           ###   @3='2009:01:01'
1116
1117       Specify --verbose or -v twice to also display data types and some
1118       metadata for each column, and informational log events such as row
1119       query log events if the binlog_rows_query_log_events system variable is
1120       set to TRUE. The output contains an additional comment following each
1121       column change:
1122
1123           $> mysqlbinlog -vv log_file
1124           ...
1125           # at 218
1126           #080828 15:03:08 server id 1  end_log_pos 258   Write_rows: table id 17 flags: STMT_END_F
1127           BINLOG '
1128           fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1129           fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
1130           '/*!*/;
1131           ### INSERT INTO test.t
1132           ### SET
1133           ###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
1134           ###   @2='apple' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
1135           ###   @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
1136           ...
1137           # at 302
1138           #080828 15:03:08 server id 1  end_log_pos 356   Update_rows: table id 17 flags: STMT_END_F
1139           BINLOG '
1140           fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1141           fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
1142           '/*!*/;
1143           ### UPDATE test.t
1144           ### WHERE
1145           ###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
1146           ###   @2='apple' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
1147           ###   @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
1148           ### SET
1149           ###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
1150           ###   @2='pear' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
1151           ###   @3='2009:01:01' /* DATE meta=0 nullable=1 is_null=0 */
1152           ...
1153           # at 400
1154           #080828 15:03:08 server id 1  end_log_pos 442   Delete_rows: table id 17 flags: STMT_END_F
1155           BINLOG '
1156           fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1157           fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
1158           '/*!*/;
1159           ### DELETE FROM test.t
1160           ### WHERE
1161           ###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
1162           ###   @2='pear' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
1163           ###   @3='2009:01:01' /* DATE meta=0 nullable=1 is_null=0 */
1164
1165       You can tell mysqlbinlog to suppress the BINLOG statements for row
1166       events by using the --base64-output=DECODE-ROWS option. This is similar
1167       to --base64-output=NEVER but does not exit with an error if a row event
1168       is found. The combination of --base64-output=DECODE-ROWS and --verbose
1169       provides a convenient way to see row events only as SQL statements:
1170
1171           $> mysqlbinlog -v --base64-output=DECODE-ROWS log_file
1172           ...
1173           # at 218
1174           #080828 15:03:08 server id 1  end_log_pos 258   Write_rows: table id 17 flags: STMT_END_F
1175           ### INSERT INTO test.t
1176           ### SET
1177           ###   @1=1
1178           ###   @2='apple'
1179           ###   @3=NULL
1180           ...
1181           # at 302
1182           #080828 15:03:08 server id 1  end_log_pos 356   Update_rows: table id 17 flags: STMT_END_F
1183           ### UPDATE test.t
1184           ### WHERE
1185           ###   @1=1
1186           ###   @2='apple'
1187           ###   @3=NULL
1188           ### SET
1189           ###   @1=1
1190           ###   @2='pear'
1191           ###   @3='2009:01:01'
1192           ...
1193           # at 400
1194           #080828 15:03:08 server id 1  end_log_pos 442   Delete_rows: table id 17 flags: STMT_END_F
1195           ### DELETE FROM test.t
1196           ### WHERE
1197           ###   @1=1
1198           ###   @2='pear'
1199           ###   @3='2009:01:01'
1200
1201
1202           Note
1203           You should not suppress BINLOG statements if you intend to
1204           re-execute mysqlbinlog output.
1205
1206       The SQL statements produced by --verbose for row events are much more
1207       readable than the corresponding BINLOG statements. However, they do not
1208       correspond exactly to the original SQL statements that generated the
1209       events. The following limitations apply:
1210
1211       •   The original column names are lost and replaced by @N, where N is a
1212           column number.
1213
1214       •   Character set information is not available in the binary log, which
1215           affects string column display:
1216
1217           •   There is no distinction made between corresponding binary and
1218               nonbinary string types (BINARY and CHAR, VARBINARY and VARCHAR,
1219               BLOB and TEXT). The output uses a data type of STRING for
1220               fixed-length strings and VARSTRING for variable-length strings.
1221
1222           •   For multibyte character sets, the maximum number of bytes per
1223               character is not present in the binary log, so the length for
1224               string types is displayed in bytes rather than in characters.
1225               For example, STRING(4) is used as the data type for values from
1226               either of these column types:
1227
1228                   CHAR(4) CHARACTER SET latin1
1229                   CHAR(2) CHARACTER SET ucs2
1230
1231           •   Due to the storage format for events of type UPDATE_ROWS_EVENT,
1232               UPDATE statements are displayed with the WHERE clause preceding
1233               the SET clause.
1234
1235       Proper interpretation of row events requires the information from the
1236       format description event at the beginning of the binary log. Because
1237       mysqlbinlog does not know in advance whether the rest of the log
1238       contains row events, by default it displays the format description
1239       event using a BINLOG statement in the initial part of the output.
1240
1241       If the binary log is known not to contain any events requiring a BINLOG
1242       statement (that is, no row events), the --base64-output=NEVER option
1243       can be used to prevent this header from being written.
1244

USING MYSQLBINLOG TO BACK UP BINARY LOG FILES

1246       By default, mysqlbinlog reads binary log files and displays their
1247       contents in text format. This enables you to examine events within the
1248       files more easily and to re-execute them (for example, by using the
1249       output as input to mysql).  mysqlbinlog can read log files directly
1250       from the local file system, or, with the --read-from-remote-server
1251       option, it can connect to a server and request binary log contents from
1252       that server.  mysqlbinlog writes text output to its standard output, or
1253       to the file named as the value of the --result-file=file_name option if
1254       that option is given.
1255
1256       •   mysqlbinlog Backup Capabilities
1257
1258       •   mysqlbinlog Backup Options
1259
1260       •   Static and Live Backups
1261
1262       •   Output File Naming
1263
1264       •   Example: mysqldump + mysqlbinlog for Backup and Restore
1265
1266       •   mysqlbinlog Backup Restrictions
1267       mysqlbinlog Backup Capabilities
1268
1269       mysqlbinlog can read binary log files and write new files containing
1270       the same content—that is, in binary format rather than text format.
1271       This capability enables you to easily back up a binary log in its
1272       original format.  mysqlbinlog can make a static backup, backing up a
1273       set of log files and stopping when the end of the last file is reached.
1274       It can also make a continuous (“live”) backup, staying connected to the
1275       server when it reaches the end of the last log file and continuing to
1276       copy new events as they are generated. In continuous-backup operation,
1277       mysqlbinlog runs until the connection ends (for example, when the
1278       server exits) or mysqlbinlog is forcibly terminated. When the
1279       connection ends, mysqlbinlog does not wait and retry the connection,
1280       unlike a replica server. To continue a live backup after the server has
1281       been restarted, you must also restart mysqlbinlog.
1282
1283           Important
1284           mysqlbinlog can back up both encrypted and unencrypted binary log
1285           files . However, copies of encrypted binary log files that are
1286           generated using mysqlbinlog are stored in an unencrypted format.
1287       mysqlbinlog Backup Options
1288
1289       Binary log backup requires that you invoke mysqlbinlog with two options
1290       at minimum:
1291
1292       •   The --read-from-remote-server (or -R) option tells mysqlbinlog to
1293           connect to a server and request its binary log. (This is similar to
1294           a replica server connecting to its replication source server.)
1295
1296       •   The --raw option tells mysqlbinlog to write raw (binary) output,
1297           not text output.
1298
1299       Along with --read-from-remote-server, it is common to specify other
1300       options: --host indicates where the server is running, and you may also
1301       need to specify connection options such as --user and --password.
1302
1303       Several other options are useful in conjunction with --raw:
1304
1305--stop-never: Stay connected to the server after reaching the end
1306           of the last log file and continue to read new events.
1307
1308--connection-server-id=id: The server ID that mysqlbinlog reports
1309           when it connects to a server. When --stop-never is used, the
1310           default reported server ID is 1. If this causes a conflict with the
1311           ID of a replica server or another mysqlbinlog process, use
1312           --connection-server-id to specify an alternative server ID. See the
1313           section called “SPECIFYING THE MYSQLBINLOG SERVER ID”.
1314
1315--result-file: A prefix for output file names, as described later.
1316       Static and Live Backups
1317
1318       To back up a server's binary log files with mysqlbinlog, you must
1319       specify file names that actually exist on the server. If you do not
1320       know the names, connect to the server and use the SHOW BINARY LOGS
1321       statement to see the current names. Suppose that the statement produces
1322       this output:
1323
1324           mysql> SHOW BINARY LOGS;
1325           +---------------+-----------+-----------+
1326           | Log_name      | File_size | Encrypted |
1327           +---------------+-----------+-----------+
1328           | binlog.000130 |     27459 | No        |
1329           | binlog.000131 |     13719 | No        |
1330           | binlog.000132 |     43268 | No        |
1331           +---------------+-----------+-----------+
1332
1333       With that information, you can use mysqlbinlog to back up the binary
1334       log to the current directory as follows (enter each command on a single
1335       line):
1336
1337       •   To make a static backup of binlog.000130 through binlog.000132, use
1338           either of these commands:
1339
1340               mysqlbinlog --read-from-remote-server --host=host_name --raw
1341                 binlog.000130 binlog.000131 binlog.000132
1342               mysqlbinlog --read-from-remote-server --host=host_name --raw
1343                 --to-last-log binlog.000130
1344
1345           The first command specifies every file name explicitly. The second
1346           names only the first file and uses --to-last-log to read through
1347           the last. A difference between these commands is that if the server
1348           happens to open binlog.000133 before mysqlbinlog reaches the end of
1349           binlog.000132, the first command does not read it, but the second
1350           command does.
1351
1352       •   To make a live backup in which mysqlbinlog starts with
1353           binlog.000130 to copy existing log files, then stays connected to
1354           copy new events as the server generates them:
1355
1356               mysqlbinlog --read-from-remote-server --host=host_name --raw
1357                 --stop-never binlog.000130
1358
1359           With --stop-never, it is not necessary to specify --to-last-log to
1360           read to the last log file because that option is implied.
1361       Output File Naming
1362
1363       Without --raw, mysqlbinlog produces text output and the --result-file
1364       option, if given, specifies the name of the single file to which all
1365       output is written. With --raw, mysqlbinlog writes one binary output
1366       file for each log file transferred from the server. By default,
1367       mysqlbinlog writes the files in the current directory with the same
1368       names as the original log files. To modify the output file names, use
1369       the --result-file option. In conjunction with --raw, the --result-file
1370       option value is treated as a prefix that modifies the output file
1371       names.
1372
1373       Suppose that a server currently has binary log files named
1374       binlog.000999 and up. If you use mysqlbinlog --raw to back up the
1375       files, the --result-file option produces output file names as shown in
1376       the following table. You can write the files to a specific directory by
1377       beginning the --result-file value with the directory path. If the
1378       --result-file value consists only of a directory name, the value must
1379       end with the pathname separator character. Output files are overwritten
1380       if they exist.
1381
1382       ┌─────────────────────┬────────────────────────────┐
1383--result-file Option │ Output File Names          
1384       ├─────────────────────┼────────────────────────────┤
1385--result-file=x      │ xbinlog.000999 and up      │
1386       ├─────────────────────┼────────────────────────────┤
1387--result-file=/tmp/  │ /tmp/binlog.000999 and up  │
1388       ├─────────────────────┼────────────────────────────┤
1389--result-file=/tmp/x │ /tmp/xbinlog.000999 and up │
1390       └─────────────────────┴────────────────────────────┘
1391       Example: mysqldump + mysqlbinlog for Backup and Restore
1392
1393       The following example describes a simple scenario that shows how to use
1394       mysqldump and mysqlbinlog together to back up a server's data and
1395       binary log, and how to use the backup to restore the server if data
1396       loss occurs. The example assumes that the server is running on host
1397       host_name and its first binary log file is named binlog.000999. Enter
1398       each command on a single line.
1399
1400       Use mysqlbinlog to make a continuous backup of the binary log:
1401
1402           mysqlbinlog --read-from-remote-server --host=host_name --raw
1403             --stop-never binlog.000999
1404
1405       Use mysqldump to create a dump file as a snapshot of the server's data.
1406       Use --all-databases, --events, and --routines to back up all data, and
1407       --master-data=2 to include the current binary log coordinates in the
1408       dump file.
1409
1410           mysqldump --host=host_name --all-databases --events --routines --master-data=2> dump_file
1411
1412       Execute the mysqldump command periodically to create newer snapshots as
1413       desired.
1414
1415       If data loss occurs (for example, if the server unexpectedly exits),
1416       use the most recent dump file to restore the data:
1417
1418           mysql --host=host_name -u root -p < dump_file
1419
1420       Then use the binary log backup to re-execute events that were written
1421       after the coordinates listed in the dump file. Suppose that the
1422       coordinates in the file look like this:
1423
1424           -- CHANGE MASTER TO MASTER_LOG_FILE='binlog.001002', MASTER_LOG_POS=27284;
1425
1426       If the most recent backed-up log file is named binlog.001004,
1427       re-execute the log events like this:
1428
1429           mysqlbinlog --start-position=27284 binlog.001002 binlog.001003 binlog.001004
1430             | mysql --host=host_name -u root -p
1431
1432       You might find it easier to copy the backup files (dump file and binary
1433       log files) to the server host to make it easier to perform the restore
1434       operation, or if MySQL does not allow remote root access.  mysqlbinlog
1435       Backup Restrictions
1436
1437       Binary log backups with mysqlbinlog are subject to these restrictions:
1438
1439mysqlbinlog does not automatically reconnect to the MySQL server if
1440           the connection is lost (for example, if a server restart occurs or
1441           there is a network outage).
1442
1443       •   The delay for a backup is similar to the delay for a replica
1444           server.
1445

SPECIFYING THE MYSQLBINLOG SERVER ID

1447       When invoked with the --read-from-remote-server option, mysqlbinlog
1448       connects to a MySQL server, specifies a server ID to identify itself,
1449       and requests binary log files from the server. You can use mysqlbinlog
1450       to request log files from a server in several ways:
1451
1452       •   Specify an explicitly named set of files: For each file,
1453           mysqlbinlog connects and issues a Binlog dump command. The server
1454           sends the file and disconnects. There is one connection per file.
1455
1456       •   Specify the beginning file and --to-last-log: mysqlbinlog connects
1457           and issues a Binlog dump command for all files. The server sends
1458           all files and disconnects.
1459
1460       •   Specify the beginning file and --stop-never (which implies
1461           --to-last-log): mysqlbinlog connects and issues a Binlog dump
1462           command for all files. The server sends all files, but does not
1463           disconnect after sending the last one.
1464
1465       With --read-from-remote-server only, mysqlbinlog connects using a
1466       server ID of 0, which tells the server to disconnect after sending the
1467       last requested log file.
1468
1469       With --read-from-remote-server and --stop-never, mysqlbinlog connects
1470       using a nonzero server ID, so the server does not disconnect after
1471       sending the last log file. The server ID is 1 by default, but this can
1472       be changed with --connection-server-id.
1473
1474       Thus, for the first two ways of requesting files, the server
1475       disconnects because mysqlbinlog specifies a server ID of 0. It does not
1476       disconnect if --stop-never is given because mysqlbinlog specifies a
1477       nonzero server ID.
1478
1480       Copyright © 1997, 2023, Oracle and/or its affiliates.
1481
1482       This documentation is free software; you can redistribute it and/or
1483       modify it only under the terms of the GNU General Public License as
1484       published by the Free Software Foundation; version 2 of the License.
1485
1486       This documentation is distributed in the hope that it will be useful,
1487       but WITHOUT ANY WARRANTY; without even the implied warranty of
1488       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1489       General Public License for more details.
1490
1491       You should have received a copy of the GNU General Public License along
1492       with the program; if not, write to the Free Software Foundation, Inc.,
1493       51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see
1494       http://www.gnu.org/licenses/.
1495
1496

NOTES

1498        1. MySQL Internals: The Binary Log
1499           https://dev.mysql.com/doc/internals/en/binary-log.html
1500

SEE ALSO

1502       For more information, please refer to the MySQL Reference Manual, which
1503       may already be installed locally and which is also available online at
1504       http://dev.mysql.com/doc/.
1505

AUTHOR

1507       Oracle Corporation (http://dev.mysql.com/).
1508
1509
1510
1511MySQL 8.0                         08/31/2023                    MYSQLBINLOG(1)
Impressum