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.0000003
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.
377
378--force-read, -f With this option, if mysqlbinlog reads a binary
379           log event that it does not recognize, it prints a warning, ignores
380           the event, and continues. Without this option, mysqlbinlog stops if
381           it reads such an event.
382
383--get-server-public-key Request from the server the public key
384           required for RSA key pair-based password exchange. This option
385           applies to clients that authenticate with the caching_sha2_password
386           authentication plugin. For that plugin, the server does not send
387           the public key unless requested. This option is ignored for
388           accounts that do not authenticate with that plugin. It is also
389           ignored if RSA-based password exchange is not used, as is the case
390           when the client connects to the server using a secure connection.
391
392           If --server-public-key-path=file_name is given and specifies a
393           valid public key file, it takes precedence over
394           --get-server-public-key.
395
396           For information about the caching_sha2_password plugin, see
397           Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.
398
399--hexdump, -H Display a hex dump of the log in comments, as
400           described in the section called “MYSQLBINLOG HEX DUMP FORMAT”. The
401           hex output can be helpful for replication debugging.
402
403--host=host_name, -h host_name Get the binary log from the MySQL
404           server on the given host.
405
406--idempotent Tell the MySQL Server to use idempotent mode while
407           processing updates; this causes suppression of any duplicate-key or
408           key-not-found errors that the server encounters in the current
409           session while processing updates. This option may prove useful
410           whenever it is desirable or necessary to replay one or more binary
411           logs to a MySQL Server which may not contain all of the data to
412           which the logs refer.
413
414           The scope of effect for this option includes the current
415           mysqlbinlog client and session only.
416
417--include-gtids=gtid_set Display only the groups listed in the
418           gtid_set.
419
420--local-load=dir_name, -l dir_name For data loading operations
421           corresponding to LOAD DATA statements, mysqlbinlog extracts the
422           files from the binary log events, writes them as temporary files to
423           the local file system, and writes LOAD DATA LOCAL statements to
424           cause the files to be loaded. By default, mysqlbinlog writes these
425           temporary files to an operating system-specific directory. The
426           --local-load option can be used to explicitly specify the directory
427           where mysqlbinlog should prepare local temporary files.
428
429           Because other processes can write files to the default
430           system-specific directory, it is advisable to specify the
431           --local-load option to mysqlbinlog to designate a different
432           directory for data files, and then designate that same directory by
433           specifying the --load-data-local-dir option to mysql when
434           processing the output from mysqlbinlog. For example:
435
436               mysqlbinlog --local-load=/my/local/data ...
437                   | mysql --load-data-local-dir=/my/local/data ...
438
439               Important
440               These temporary files are not automatically removed by
441               mysqlbinlog or any other MySQL program.
442
443--login-path=name Read options from the named login path in the
444           .mylogin.cnf login path file. A “login path” is an option group
445           containing options that specify which MySQL server to connect to
446           and which account to authenticate as. To create or modify a login
447           path file, use the mysql_config_editor utility. See
448           mysql_config_editor(1).
449
450           For additional information about this and other option-file
451           options, see Section 4.2.2.3, “Command-Line Options that Affect
452           Option-File Handling”.
453
454--no-defaults Do not read any option files. If program startup
455           fails due to reading unknown options from an option file,
456           --no-defaults can be used to prevent them from being read.
457
458           The exception is that the .mylogin.cnf file is read in all cases,
459           if it exists. This permits passwords to be specified in a safer way
460           than on the command line even when --no-defaults is used. To create
461           .mylogin.cnf, use the mysql_config_editor utility. See
462           mysql_config_editor(1).
463
464           For additional information about this and other option-file
465           options, see Section 4.2.2.3, “Command-Line Options that Affect
466           Option-File Handling”.
467
468--offset=N, -o N Skip the first N entries in the log.
469
470--open-files-limit=N Specify the number of open file descriptors to
471           reserve.
472
473--password[=password], -p[password] The password of the MySQL
474           account used for connecting to the server. The password value is
475           optional. If not given, mysqlbinlog prompts for one. If given,
476           there must be no space between --password= or -p and the password
477           following it. If no password option is specified, the default is to
478           send no password.
479
480           Specifying a password on the command line should be considered
481           insecure. To avoid giving the password on the command line, use an
482           option file. See Section 6.1.2.1, “End-User Guidelines for Password
483           Security”.
484
485           To explicitly specify that there is no password and that
486           mysqlbinlog should not prompt for one, use the --skip-password
487           option.
488
489--plugin-dir=dir_name The directory in which to look for plugins.
490           Specify this option if the --default-auth option is used to specify
491           an authentication plugin but mysqlbinlog does not find it. See
492           Section 6.2.17, “Pluggable Authentication”.
493
494--port=port_num, -P port_num The TCP/IP port number to use for
495           connecting to a remote server.
496
497--print-defaults Print the program name and all options that it
498           gets from option files.
499
500           For additional information about this and other option-file
501           options, see Section 4.2.2.3, “Command-Line Options that Affect
502           Option-File Handling”.
503
504--print-table-metadata Print table related metadata from the binary
505           log. Configure the amount of table related metadata binary logged
506           using binlog-row-metadata.
507
508--protocol={TCP|SOCKET|PIPE|MEMORY} The transport protocol to use
509           for connecting to the server. It is useful when the other
510           connection parameters normally result in use of a protocol other
511           than the one you want. For details on the permissible values, see
512           Section 4.2.7, “Connection Transport Protocols”.
513
514--raw By default, mysqlbinlog reads binary log files and writes
515           events in text format. The --raw option tells mysqlbinlog to write
516           them in their original binary format. Its use requires that
517           --read-from-remote-server also be used because the files are
518           requested from a server.  mysqlbinlog writes one output file for
519           each file read from the server. The --raw option can be used to
520           make a backup of a server's binary log. With the --stop-never
521           option, the backup is “live” because mysqlbinlog stays connected to
522           the server. By default, output files are written in the current
523           directory with the same names as the original log files. Output
524           file names can be modified using the --result-file option. For more
525           information, see the section called “USING MYSQLBINLOG TO BACK UP
526           BINARY LOG FILES”.
527
528--read-from-remote-source=type From MySQL 8.0.26, use
529           --read-from-remote-source, and before MySQL 8.0.26, use
530           --read-from-remote-master. Both options have the same effect. The
531           options read binary logs from a MySQL server with the
532           COM_BINLOG_DUMP or COM_BINLOG_DUMP_GTID commands by setting the
533           option value to either BINLOG-DUMP-NON-GTIDS or BINLOG-DUMP-GTIDS,
534           respectively. If --read-from-remote-source=BINLOG-DUMP-GTIDS or
535           --read-from-remote-master=BINLOG-DUMP-GTIDS is combined with
536           --exclude-gtids, transactions can be filtered out on the source,
537           avoiding unnecessary network traffic.
538
539           The connection parameter options are used with these options or the
540           --read-from-remote-server option. These options are --host,
541           --password, --port, --protocol, --socket, and --user. If none of
542           the remote options is specified, the connection parameter options
543           are ignored.
544
545           The REPLICATION SLAVE privilege is required to use these options.
546
547--read-from-remote-master=type Use this option before MySQL 8.0.26
548           rather than --read-from-remote-source. Both options have the same
549           effect.
550
551--read-from-remote-server, -R Read the binary log from a MySQL
552           server rather than reading a local log file. This option requires
553           that the remote server be running. It works only for binary log
554           files on the remote server, not relay log files.
555
556           The connection parameter options are used with this option or the
557           --read-from-remote-master option. These options are --host,
558           --password, --port, --protocol, --socket, and --user. If neither of
559           the remote options is specified, the connection parameter options
560           are ignored.
561
562           The REPLICATION SLAVE privilege is required to use this option.
563
564           This option is like
565           --read-from-remote-master=BINLOG-DUMP-NON-GTIDS.
566
567--result-file=name, -r name Without the --raw option, this option
568           indicates the file to which mysqlbinlog writes text output. With
569           --raw, mysqlbinlog writes one binary output file for each log file
570           transferred from the server, writing them by default in the current
571           directory using the same names as the original log file. In this
572           case, the --result-file option value is treated as a prefix that
573           modifies output file names.
574
575--require-row-format Require row-based binary logging format for
576           events. This option enforces row-based replication events for
577           mysqlbinlog output. The stream of events produced with this option
578           would be accepted by a replication channel that is secured using
579           the REQUIRE_ROW_FORMAT option of the CHANGE REPLICATION SOURCE TO
580           statement (from MySQL 8.0.23) or CHANGE MASTER TO statement (before
581           MySQL 8.0.23).  binlog_format=ROW must be set on the server where
582           the binary log was written. When you specify this option,
583           mysqlbinlog stops with an error message if it encounters any events
584           that are disallowed under the REQUIRE_ROW_FORMAT restrictions,
585           including LOAD DATA INFILE instructions, creating or dropping
586           temporary tables, INTVAR, RAND, or USER_VAR events, and
587           non-row-based events within a DML transaction.  mysqlbinlog also
588           prints a SET @@session.require_row_format statement at the start of
589           its output to apply the restrictions when the output is executed,
590           and does not print the SET @@session.pseudo_thread_id statement.
591
592           This option was added in MySQL 8.0.19.
593
594--rewrite-db='from_name->to_name' When reading from a row-based or
595           statement-based log, rewrite all occurrences of from_name to
596           to_name. Rewriting is done on the rows, for row-based logs, as well
597           as on the USE clauses, for statement-based logs.
598
599               Warning
600               Statements in which table names are qualified with database
601               names are not rewritten to use the new name when using this
602               option.
603           The rewrite rule employed as a value for this option is a string
604           having the form 'from_name->to_name', as shown previously, and for
605           this reason must be enclosed by quotation marks.
606
607           To employ multiple rewrite rules, specify the option multiple
608           times, as shown here:
609
610               mysqlbinlog --rewrite-db='dbcurrent->dbold' --rewrite-db='dbtest->dbcurrent' \
611                   binlog.00001 > /tmp/statements.sql
612
613           When used together with the --database option, the --rewrite-db
614           option is applied first; then --database option is applied, using
615           the rewritten database name. The order in which the options are
616           provided makes no difference in this regard.
617
618           This means that, for example, if mysqlbinlog is started with
619           --rewrite-db='mydb->yourdb' --database=yourdb, then all updates to
620           any tables in databases mydb and yourdb are included in the output.
621           On the other hand, if it is started with
622           --rewrite-db='mydb->yourdb' --database=mydb, then mysqlbinlog
623           outputs no statements at all: since all updates to mydb are first
624           rewritten as updates to yourdb before applying the --database
625           option, there remain no updates that match --database=mydb.
626
627--server-id=id Display only those events created by the server
628           having the given server ID.
629
630--server-id-bits=N Use only the first N bits of the server_id to
631           identify the server. If the binary log was written by a mysqld with
632           server-id-bits set to less than 32 and user data stored in the most
633           significant bit, running mysqlbinlog with --server-id-bits set to
634           32 enables this data to be seen.
635
636           This option is supported only by the version of mysqlbinlog
637           supplied with the NDB Cluster distribution, or built with NDB
638           Cluster support.
639
640--server-public-key-path=file_name The path name to a file in PEM
641           format containing a client-side copy of the public key required by
642           the server for RSA key pair-based password exchange. This option
643           applies to clients that authenticate with the sha256_password or
644           caching_sha2_password authentication plugin. This option is ignored
645           for accounts that do not authenticate with one of those plugins. It
646           is also ignored if RSA-based password exchange is not used, as is
647           the case when the client connects to the server using a secure
648           connection.
649
650           If --server-public-key-path=file_name is given and specifies a
651           valid public key file, it takes precedence over
652           --get-server-public-key.
653
654           For sha256_password, this option applies only if MySQL was built
655           using OpenSSL.
656
657           For information about the sha256_password and caching_sha2_password
658           plugins, see Section 6.4.1.3, “SHA-256 Pluggable Authentication”,
659           and Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.
660
661--set-charset=charset_name Add a SET NAMES charset_name statement
662           to the output to specify the character set to be used for
663           processing log files.
664
665--shared-memory-base-name=name On Windows, the shared-memory name
666           to use for connections made using shared memory to a local server.
667           The default value is MYSQL. The shared-memory name is
668           case-sensitive.
669
670           This option applies only if the server was started with the
671           shared_memory system variable enabled to support shared-memory
672           connections.
673
674--short-form, -s Display only the statements contained in the log,
675           without any extra information or row-based events. This is for
676           testing only, and should not be used in production systems. It is
677           deprecated, and you should expect it to be removed in a future
678           release.
679
680--skip-gtids[=(true|false)] Do not display any GTIDs in the output.
681           This is needed when writing to a dump file from one or more binary
682           logs containing GTIDs, as shown in this example:
683
684               mysqlbinlog --skip-gtids binlog.000001 >  /tmp/dump.sql
685               mysqlbinlog --skip-gtids binlog.000002 >> /tmp/dump.sql
686               mysql -u root -p -e "source /tmp/dump.sql"
687
688           The use of this option is otherwise not normally recommended in
689           production.
690
691--socket=path, -S path For connections to localhost, the Unix
692           socket file to use, or, on Windows, the name of the named pipe to
693           use.
694
695           On Windows, this option applies only if the server was started with
696           the named_pipe system variable enabled to support named-pipe
697           connections. In addition, the user making the connection must be a
698           member of the Windows group specified by the
699           named_pipe_full_access_group system variable.
700
701--ssl* Options that begin with --ssl specify whether to connect to
702           the server using encryption and indicate where to find SSL keys and
703           certificates. See the section called “Command Options for Encrypted
704           Connections”.
705
706--ssl-fips-mode={OFF|ON|STRICT} Controls whether to enable FIPS
707           mode on the client side. The --ssl-fips-mode option differs from
708           other --ssl-xxx options in that it is not used to establish
709           encrypted connections, but rather to affect which cryptographic
710           operations to permit. See Section 6.8, “FIPS Support”.
711
712           These --ssl-fips-mode values are permitted:
713
714           •   OFF: Disable FIPS mode.
715
716           •   ON: Enable FIPS mode.
717
718           •   STRICT: Enable “strict” FIPS mode.
719
720
721               Note
722               If the OpenSSL FIPS Object Module is not available, the only
723               permitted value for --ssl-fips-mode is OFF. In this case,
724               setting --ssl-fips-mode to ON or STRICT causes the client to
725               produce a warning at startup and to operate in non-FIPS mode.
726
727--start-datetime=datetime Start reading the binary log at the first
728           event having a timestamp equal to or later than the datetime
729           argument. The datetime value is relative to the local time zone on
730           the machine where you run mysqlbinlog. The value should be in a
731           format accepted for the DATETIME or TIMESTAMP data types. For
732           example:
733
734               mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000003
735
736           This option is useful for point-in-time recovery. See Section 7.5,
737           “Point-in-Time (Incremental) Recovery”.
738
739--start-position=N, -j N Start decoding the binary log at the log
740           position N, including in the output any events that begin at
741           position N or after. The position is a byte point in the log file,
742           not an event counter; it needs to point to the starting position of
743           an event to generate useful output. This option applies to the
744           first log file named on the command line.
745
746           This option is useful for point-in-time recovery. See Section 7.5,
747           “Point-in-Time (Incremental) Recovery”.
748
749--stop-datetime=datetime Stop reading the binary log at the first
750           event having a timestamp equal to or later than the datetime
751           argument. See the description of the --start-datetime option for
752           information about the datetime value.
753
754           This option is useful for point-in-time recovery. See Section 7.5,
755           “Point-in-Time (Incremental) Recovery”.
756
757--stop-never This option is used with --read-from-remote-server. It
758           tells mysqlbinlog to remain connected to the server. Otherwise
759           mysqlbinlog exits when the last log file has been transferred from
760           the server.  --stop-never implies --to-last-log, so only the first
761           log file to transfer need be named on the command line.
762
763           --stop-never is commonly used with --raw to make a live binary log
764           backup, but also can be used without --raw to maintain a continuous
765           text display of log events as the server generates them.
766
767           With --stop-never, by default, mysqlbinlog reports a server ID of 1
768           when it connects to the server. Use --connection-server-id to
769           explicitly specify an alternative ID to report. It can be used to
770           avoid a conflict with the ID of a replica server or another
771           mysqlbinlog process. See the section called “SPECIFYING THE
772           MYSQLBINLOG SERVER ID”.
773
774--stop-never-slave-server-id=id This option is deprecated; expect
775           it to be removed in a future release. Use the
776           --connection-server-id option instead to specify a server ID for
777           mysqlbinlog to report.
778
779--stop-position=N Stop decoding the binary log at the log position
780           N, excluding from the output any events that begin at position N or
781           after. The position is a byte point in the log file, not an event
782           counter; it needs to point to a spot after the starting position of
783           the last event you want to include in the output. The event
784           starting before position N and finishing at or after the position
785           is the last event to be processed. This option applies to the last
786           log file named on the command line.
787
788           This option is useful for point-in-time recovery. See Section 7.5,
789           “Point-in-Time (Incremental) Recovery”.
790
791--tls-ciphersuites=ciphersuite_list The permissible ciphersuites
792           for encrypted connections that use TLSv1.3. The value is a list of
793           one or more colon-separated ciphersuite names. The ciphersuites
794           that can be named for this option depend on the SSL library used to
795           compile MySQL. For details, see Section 6.3.2, “Encrypted
796           Connection TLS Protocols and Ciphers”.
797
798           This option was added in MySQL 8.0.16.
799
800--tls-version=protocol_list The permissible TLS protocols for
801           encrypted connections. The value is a list of one or more
802           comma-separated protocol names. The protocols that can be named for
803           this option depend on the SSL library used to compile MySQL. For
804           details, see Section 6.3.2, “Encrypted Connection TLS Protocols and
805           Ciphers”.
806
807--to-last-log, -t Do not stop at the end of the requested binary
808           log from a MySQL server, but rather continue printing until the end
809           of the last binary log. If you send the output to the same MySQL
810           server, this may lead to an endless loop. This option requires
811           --read-from-remote-server.
812
813--user=user_name, -u user_name The user name of the MySQL account
814           to use when connecting to a remote server.
815
816--verbose, -v Reconstruct row events and display them as commented
817           SQL statements, with table partition information where applicable.
818           If this option is given twice (by passing in either "-vv" or
819           "--verbose --verbose"), the output includes comments to indicate
820           column data types and some metadata, and informational log events
821           such as row query log events if the binlog_rows_query_log_events
822           system variable is set to TRUE.
823
824           For examples that show the effect of --base64-output and --verbose
825           on row event output, see the section called “MYSQLBINLOG ROW EVENT
826           DISPLAY”.
827
828--verify-binlog-checksum, -c Verify checksums in binary log files.
829
830--version, -V Display version information and exit.
831
832           The mysqlbinlog version number shown when using this option is 3.4.
833
834--zstd-compression-level=level The compression level to use for
835           connections to the server that use the zstd compression algorithm.
836           The permitted levels are from 1 to 22, with larger values
837           indicating increasing levels of compression. The default zstd
838           compression level is 3. The compression level setting has no effect
839           on connections that do not use zstd compression.
840
841           For more information, see Section 4.2.8, “Connection Compression
842           Control”.
843
844           This option was added in MySQL 8.0.18.
845
846       You can pipe the output of mysqlbinlog into the mysql client to execute
847       the events contained in the binary log. This technique is used to
848       recover from an unexpected exit when you have an old backup (see
849       Section 7.5, “Point-in-Time (Incremental) Recovery”). For example:
850
851           mysqlbinlog binlog.000001 | mysql -u root -p
852
853       Or:
854
855           mysqlbinlog binlog.[0-9]* | mysql -u root -p
856
857       If the statements produced by mysqlbinlog may contain BLOB values,
858       these may cause problems when mysql processes them. In this case,
859       invoke mysql with the --binary-mode option.
860
861       You can also redirect the output of mysqlbinlog to a text file instead,
862       if you need to modify the statement log first (for example, to remove
863       statements that you do not want to execute for some reason). After
864       editing the file, execute the statements that it contains by using it
865       as input to the mysql program:
866
867           mysqlbinlog binlog.000001 > tmpfile
868           ... edit tmpfile ...
869           mysql -u root -p < tmpfile
870
871       When mysqlbinlog is invoked with the --start-position option, it
872       displays only those events with an offset in the binary log greater
873       than or equal to a given position (the given position must match the
874       start of one event). It also has options to stop and start when it sees
875       an event with a given date and time. This enables you to perform
876       point-in-time recovery using the --stop-datetime option (to be able to
877       say, for example, “roll forward my databases to how they were today at
878       10:30 a.m.”).
879
880       Processing multiple files. If you have more than one binary log to
881       execute on the MySQL server, the safe method is to process them all
882       using a single connection to the server. Here is an example that
883       demonstrates what may be unsafe:
884
885           mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
886           mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!
887
888       Processing binary logs this way using multiple connections to the
889       server causes problems if the first log file contains a CREATE
890       TEMPORARY TABLE statement and the second log contains a statement that
891       uses the temporary table. When the first mysql process terminates, the
892       server drops the temporary table. When the second mysql process
893       attempts to use the table, the server reports “unknown table.”
894
895       To avoid problems like this, use a single mysql process to execute the
896       contents of all binary logs that you want to process. Here is one way
897       to do so:
898
899           mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
900
901       Another approach is to write all the logs to a single file and then
902       process the file:
903
904           mysqlbinlog binlog.000001 >  /tmp/statements.sql
905           mysqlbinlog binlog.000002 >> /tmp/statements.sql
906           mysql -u root -p -e "source /tmp/statements.sql"
907
908       From MySQL 8.0.12, you can also supply multiple binary log files to
909       mysqlbinlog as streamed input using a shell pipe. An archive of
910       compressed binary log files can be decompressed and provided directly
911       to mysqlbinlog. In this example, binlog-files_1.gz contains multiple
912       binary log files for processing. The pipeline extracts the contents of
913       binlog-files_1.gz, pipes the binary log files to mysqlbinlog as
914       standard input, and pipes the output of mysqlbinlog into the mysql
915       client for execution:
916
917           gzip -cd binlog-files_1.gz | ./mysqlbinlog - | ./mysql -uroot  -p
918
919       You can specify more than one archive file, for example:
920
921           gzip -cd binlog-files_1.gz binlog-files_2.gz | ./mysqlbinlog - | ./mysql -uroot  -p
922
923       For streamed input, do not use --stop-position, because mysqlbinlog
924       cannot identify the last log file to apply this option.
925
926       LOAD DATA operations. mysqlbinlog can produce output that reproduces a
927       LOAD DATA operation without the original data file.  mysqlbinlog copies
928       the data to a temporary file and writes a LOAD DATA LOCAL statement
929       that refers to the file. The default location of the directory where
930       these files are written is system-specific. To specify a directory
931       explicitly, use the --local-load option.
932
933       Because mysqlbinlog converts LOAD DATA statements to LOAD DATA LOCAL
934       statements (that is, it adds LOCAL), both the client and the server
935       that you use to process the statements must be configured with the
936       LOCAL capability enabled. See Section 6.1.6, “Security Considerations
937       for LOAD DATA LOCAL”.
938
939           Warning
940           The temporary files created for LOAD DATA LOCAL statements are not
941           automatically deleted because they are needed until you actually
942           execute those statements. You should delete the temporary files
943           yourself after you no longer need the statement log. The files can
944           be found in the temporary file directory and have names like
945           original_file_name-#-#.
946

MYSQLBINLOG HEX DUMP FORMAT

948       The --hexdump option causes mysqlbinlog to produce a hex dump of the
949       binary log contents:
950
951           mysqlbinlog --hexdump source-bin.000001
952
953       The hex output consists of comment lines beginning with #, so the
954       output might look like this for the preceding command:
955
956           /*!40019 SET @@SESSION.max_insert_delayed_threads=0*/;
957           /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
958           # at 4
959           #051024 17:24:13 server id 1  end_log_pos 98
960           # Position  Timestamp   Type   Master ID        Size      Master Pos    Flags
961           # 00000004 9d fc 5c 43   0f   01 00 00 00   5e 00 00 00   62 00 00 00   00 00
962           # 00000017 04 00 35 2e 30 2e 31 35  2d 64 65 62 75 67 2d 6c |..5.0.15.debug.l|
963           # 00000027 6f 67 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |og..............|
964           # 00000037 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |................|
965           # 00000047 00 00 00 00 9d fc 5c 43  13 38 0d 00 08 00 12 00 |.......C.8......|
966           # 00000057 04 04 04 04 12 00 00 4b  00 04 1a                |.......K...|
967           #       Start: binlog v 4, server v 5.0.15-debug-log created 051024 17:24:13
968           #       at startup
969           ROLLBACK;
970
971       Hex dump output currently contains the elements in the following list.
972       This format is subject to change. For more information about binary log
973       format, see MySQL Internals: The Binary Log[1].
974
975       •   Position: The byte position within the log file.
976
977       •   Timestamp: The event timestamp. In the example shown, '9d fc 5c 43'
978           is the representation of '051024 17:24:13' in hexadecimal.
979
980       •   Type: The event type code.
981
982       •   Master ID: The server ID of the replication source server that
983           created the event.
984
985       •   Size: The size in bytes of the event.
986
987       •   Master Pos: The position of the next event in the original source's
988           binary log file.
989
990       •   Flags: Event flag values.
991

MYSQLBINLOG ROW EVENT DISPLAY

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

USING MYSQLBINLOG TO BACK UP BINARY LOG FILES

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

SPECIFYING THE MYSQLBINLOG SERVER ID

1419       When invoked with the --read-from-remote-server option, mysqlbinlog
1420       connects to a MySQL server, specifies a server ID to identify itself,
1421       and requests binary log files from the server. You can use mysqlbinlog
1422       to request log files from a server in several ways:
1423
1424       •   Specify an explicitly named set of files: For each file,
1425           mysqlbinlog connects and issues a Binlog dump command. The server
1426           sends the file and disconnects. There is one connection per file.
1427
1428       •   Specify the beginning file and --to-last-log: mysqlbinlog connects
1429           and issues a Binlog dump command for all files. The server sends
1430           all files and disconnects.
1431
1432       •   Specify the beginning file and --stop-never (which implies
1433           --to-last-log): mysqlbinlog connects and issues a Binlog dump
1434           command for all files. The server sends all files, but does not
1435           disconnect after sending the last one.
1436
1437       With --read-from-remote-server only, mysqlbinlog connects using a
1438       server ID of 0, which tells the server to disconnect after sending the
1439       last requested log file.
1440
1441       With --read-from-remote-server and --stop-never, mysqlbinlog connects
1442       using a nonzero server ID, so the server does not disconnect after
1443       sending the last log file. The server ID is 1 by default, but this can
1444       be changed with --connection-server-id.
1445
1446       Thus, for the first two ways of requesting files, the server
1447       disconnects because mysqlbinlog specifies a server ID of 0. It does not
1448       disconnect if --stop-never is given because mysqlbinlog specifies a
1449       nonzero server ID.
1450
1452       Copyright © 1997, 2021, Oracle and/or its affiliates.
1453
1454       This documentation is free software; you can redistribute it and/or
1455       modify it only under the terms of the GNU General Public License as
1456       published by the Free Software Foundation; version 2 of the License.
1457
1458       This documentation is distributed in the hope that it will be useful,
1459       but WITHOUT ANY WARRANTY; without even the implied warranty of
1460       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1461       General Public License for more details.
1462
1463       You should have received a copy of the GNU General Public License along
1464       with the program; if not, write to the Free Software Foundation, Inc.,
1465       51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see
1466       http://www.gnu.org/licenses/.
1467
1468

NOTES

1470        1. MySQL Internals: The Binary Log
1471           https://dev.mysql.com/doc/internals/en/binary-log.html
1472

SEE ALSO

1474       For more information, please refer to the MySQL Reference Manual, which
1475       may already be installed locally and which is also available online at
1476       http://dev.mysql.com/doc/.
1477

AUTHOR

1479       Oracle Corporation (http://dev.mysql.com/).
1480
1481
1482
1483MySQL 8.0                         11/26/2021                    MYSQLBINLOG(1)
Impressum