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_slave_mode to true before
132       executing any SQL statements. This system variable affects the handling
133       of XA transactions, the original_commit_timestamp replication delay
134       timestamp and the original_server_version system variable, and
135       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-master=type Read binary logs from a MySQL server
529           with the COM_BINLOG_DUMP or COM_BINLOG_DUMP_GTID commands by
530           setting the option value to either BINLOG-DUMP-NON-GTIDS or
531           BINLOG-DUMP-GTIDS, respectively. If
532           --read-from-remote-master=BINLOG-DUMP-GTIDS is combined with
533           --exclude-gtids, transactions can be filtered out on the source,
534           avoiding unnecessary network traffic.
535
536           The connection parameter options are used with this option or the
537           --read-from-remote-server option. These options are --host,
538           --password, --port, --protocol, --socket, and --user. If neither of
539           the remote options is specified, the connection parameter options
540           are ignored.
541
542           The REPLICATION SLAVE privilege is required to use this option.
543
544--read-from-remote-server, -R Read the binary log from a MySQL
545           server rather than reading a local log file. This option requires
546           that the remote server be running. It works only for binary log
547           files on the remote server, not relay log files.
548
549           The connection parameter options are used with this option or the
550           --read-from-remote-master option. These options are --host,
551           --password, --port, --protocol, --socket, and --user. If neither of
552           the remote options is specified, the connection parameter options
553           are ignored.
554
555           The REPLICATION SLAVE privilege is required to use this option.
556
557           This option is like
558           --read-from-remote-master=BINLOG-DUMP-NON-GTIDS.
559
560--result-file=name, -r name Without the --raw option, this option
561           indicates the file to which mysqlbinlog writes text output. With
562           --raw, mysqlbinlog writes one binary output file for each log file
563           transferred from the server, writing them by default in the current
564           directory using the same names as the original log file. In this
565           case, the --result-file option value is treated as a prefix that
566           modifies output file names.
567
568--require-row-format Require row-based binary logging format for
569           events. This option enforces row-based replication events for
570           mysqlbinlog output. The stream of events produced with this option
571           would be accepted by a replication channel that is secured using
572           the REQUIRE_ROW_FORMAT option of the CHANGE REPLICATION SOURCE TO
573           statement (from MySQL 8.0.23) or CHANGE MASTER TO statement (before
574           MySQL 8.0.23).  binlog_format=ROW must be set on the server where
575           the binary log was written. When you specify this option,
576           mysqlbinlog stops with an error message if it encounters any events
577           that are disallowed under the REQUIRE_ROW_FORMAT restrictions,
578           including LOAD DATA INFILE instructions, creating or dropping
579           temporary tables, INTVAR, RAND, or USER_VAR events, and
580           non-row-based events within a DML transaction.  mysqlbinlog also
581           prints a SET @@session.require_row_format statement at the start of
582           its output to apply the restrictions when the output is executed,
583           and does not print the SET @@session.pseudo_thread_id statement.
584
585           This option was added in MySQL 8.0.19.
586
587--rewrite-db='from_name->to_name' When reading from a row-based or
588           statement-based log, rewrite all occurrences of from_name to
589           to_name. Rewriting is done on the rows, for row-based logs, as well
590           as on the USE clauses, for statement-based logs.
591
592               Warning
593               Statements in which table names are qualified with database
594               names are not rewritten to use the new name when using this
595               option.
596           The rewrite rule employed as a value for this option is a string
597           having the form 'from_name->to_name', as shown previously, and for
598           this reason must be enclosed by quotation marks.
599
600           To employ multiple rewrite rules, specify the option multiple
601           times, as shown here:
602
603               mysqlbinlog --rewrite-db='dbcurrent->dbold' --rewrite-db='dbtest->dbcurrent' \
604                   binlog.00001 > /tmp/statements.sql
605
606           When used together with the --database option, the --rewrite-db
607           option is applied first; then --database option is applied, using
608           the rewritten database name. The order in which the options are
609           provided makes no difference in this regard.
610
611           This means that, for example, if mysqlbinlog is started with
612           --rewrite-db='mydb->yourdb' --database=yourdb, then all updates to
613           any tables in databases mydb and yourdb are included in the output.
614           On the other hand, if it is started with
615           --rewrite-db='mydb->yourdb' --database=mydb, then mysqlbinlog
616           outputs no statements at all: since all updates to mydb are first
617           rewritten as updates to yourdb before applying the --database
618           option, there remain no updates that match --database=mydb.
619
620--server-id=id Display only those events created by the server
621           having the given server ID.
622
623--server-id-bits=N Use only the first N bits of the server_id to
624           identify the server. If the binary log was written by a mysqld with
625           server-id-bits set to less than 32 and user data stored in the most
626           significant bit, running mysqlbinlog with --server-id-bits set to
627           32 enables this data to be seen.
628
629           This option is supported only by the version of mysqlbinlog
630           supplied with the NDB Cluster distribution, or built with NDB
631           Cluster support.
632
633--server-public-key-path=file_name The path name to a file in PEM
634           format containing a client-side copy of the public key required by
635           the server for RSA key pair-based password exchange. This option
636           applies to clients that authenticate with the sha256_password or
637           caching_sha2_password authentication plugin. This option is ignored
638           for accounts that do not authenticate with one of those plugins. It
639           is also ignored if RSA-based password exchange is not used, as is
640           the case when the client connects to the server using a secure
641           connection.
642
643           If --server-public-key-path=file_name is given and specifies a
644           valid public key file, it takes precedence over
645           --get-server-public-key.
646
647           For sha256_password, this option applies only if MySQL was built
648           using OpenSSL.
649
650           For information about the sha256_password and caching_sha2_password
651           plugins, see Section 6.4.1.3, “SHA-256 Pluggable Authentication”,
652           and Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.
653
654--set-charset=charset_name Add a SET NAMES charset_name statement
655           to the output to specify the character set to be used for
656           processing log files.
657
658--shared-memory-base-name=name On Windows, the shared-memory name
659           to use for connections made using shared memory to a local server.
660           The default value is MYSQL. The shared-memory name is
661           case-sensitive.
662
663           This option applies only if the server was started with the
664           shared_memory system variable enabled to support shared-memory
665           connections.
666
667--short-form, -s Display only the statements contained in the log,
668           without any extra information or row-based events. This is for
669           testing only, and should not be used in production systems. It is
670           deprecated, and you should expect it to be removed in a future
671           release.
672
673--skip-gtids[=(true|false)] Do not display any GTIDs in the output.
674           This is needed when writing to a dump file from one or more binary
675           logs containing GTIDs, as shown in this example:
676
677               mysqlbinlog --skip-gtids binlog.000001 >  /tmp/dump.sql
678               mysqlbinlog --skip-gtids binlog.000002 >> /tmp/dump.sql
679               mysql -u root -p -e "source /tmp/dump.sql"
680
681           The use of this option is otherwise not normally recommended in
682           production.
683
684--socket=path, -S path For connections to localhost, the Unix
685           socket file to use, or, on Windows, the name of the named pipe to
686           use.
687
688           On Windows, this option applies only if the server was started with
689           the named_pipe system variable enabled to support named-pipe
690           connections. In addition, the user making the connection must be a
691           member of the Windows group specified by the
692           named_pipe_full_access_group system variable.
693
694--ssl* Options that begin with --ssl specify whether to connect to
695           the server using encryption and indicate where to find SSL keys and
696           certificates. See the section called “Command Options for Encrypted
697           Connections”.
698
699--ssl-fips-mode={OFF|ON|STRICT} Controls whether to enable FIPS
700           mode on the client side. The --ssl-fips-mode option differs from
701           other --ssl-xxx options in that it is not used to establish
702           encrypted connections, but rather to affect which cryptographic
703           operations to permit. See Section 6.8, “FIPS Support”.
704
705           These --ssl-fips-mode values are permitted:
706
707           •   OFF: Disable FIPS mode.
708
709           •   ON: Enable FIPS mode.
710
711           •   STRICT: Enable “strict” FIPS mode.
712
713
714               Note
715               If the OpenSSL FIPS Object Module is not available, the only
716               permitted value for --ssl-fips-mode is OFF. In this case,
717               setting --ssl-fips-mode to ON or STRICT causes the client to
718               produce a warning at startup and to operate in non-FIPS mode.
719
720--start-datetime=datetime Start reading the binary log at the first
721           event having a timestamp equal to or later than the datetime
722           argument. The datetime value is relative to the local time zone on
723           the machine where you run mysqlbinlog. The value should be in a
724           format accepted for the DATETIME or TIMESTAMP data types. For
725           example:
726
727               mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000003
728
729           This option is useful for point-in-time recovery. See Section 7.5,
730           “Point-in-Time (Incremental) Recovery”.
731
732--start-position=N, -j N Start decoding the binary log at the log
733           position N, including in the output any events that begin at
734           position N or after. The position is a byte point in the log file,
735           not an event counter; it needs to point to the starting position of
736           an event to generate useful output. This option applies to the
737           first log file named on the command line.
738
739           This option is useful for point-in-time recovery. See Section 7.5,
740           “Point-in-Time (Incremental) Recovery”.
741
742--stop-datetime=datetime Stop reading the binary log at the first
743           event having a timestamp equal to or later than the datetime
744           argument. See the description of the --start-datetime option for
745           information about the datetime value.
746
747           This option is useful for point-in-time recovery. See Section 7.5,
748           “Point-in-Time (Incremental) Recovery”.
749
750--stop-never This option is used with --read-from-remote-server. It
751           tells mysqlbinlog to remain connected to the server. Otherwise
752           mysqlbinlog exits when the last log file has been transferred from
753           the server.  --stop-never implies --to-last-log, so only the first
754           log file to transfer need be named on the command line.
755
756           --stop-never is commonly used with --raw to make a live binary log
757           backup, but also can be used without --raw to maintain a continuous
758           text display of log events as the server generates them.
759
760           With --stop-never, by default, mysqlbinlog reports a server ID of 1
761           when it connects to the server. Use --connection-server-id to
762           explicitly specify an alternative ID to report. It can be used to
763           avoid a conflict with the ID of a replica server or another
764           mysqlbinlog process. See the section called “SPECIFYING THE
765           MYSQLBINLOG SERVER ID”.
766
767--stop-never-slave-server-id=id This option is deprecated; expect
768           it to be removed in a future release. Use the
769           --connection-server-id option instead to specify a server ID for
770           mysqlbinlog to report.
771
772--stop-position=N Stop decoding the binary log at the log position
773           N, excluding from the output any events that begin at position N or
774           after. The position is a byte point in the log file, not an event
775           counter; it needs to point to a spot after the starting position of
776           the last event you want to include in the output. The event
777           starting before position N and finishing at or after the position
778           is the last event to be processed. This option applies to the last
779           log file named on the command line.
780
781           This option is useful for point-in-time recovery. See Section 7.5,
782           “Point-in-Time (Incremental) Recovery”.
783
784--tls-ciphersuites=ciphersuite_list The permissible ciphersuites
785           for encrypted connections that use TLSv1.3. The value is a list of
786           one or more colon-separated ciphersuite names. The ciphersuites
787           that can be named for this option depend on the SSL library used to
788           compile MySQL. For details, see Section 6.3.2, “Encrypted
789           Connection TLS Protocols and Ciphers”.
790
791           This option was added in MySQL 8.0.16.
792
793--tls-version=protocol_list The permissible TLS protocols for
794           encrypted connections. The value is a list of one or more
795           comma-separated protocol names. The protocols that can be named for
796           this option depend on the SSL library used to compile MySQL. For
797           details, see Section 6.3.2, “Encrypted Connection TLS Protocols and
798           Ciphers”.
799
800--to-last-log, -t Do not stop at the end of the requested binary
801           log from a MySQL server, but rather continue printing until the end
802           of the last binary log. If you send the output to the same MySQL
803           server, this may lead to an endless loop. This option requires
804           --read-from-remote-server.
805
806--user=user_name, -u user_name The user name of the MySQL account
807           to use when connecting to a remote server.
808
809--verbose, -v Reconstruct row events and display them as commented
810           SQL statements, with table partition information where applicable.
811           If this option is given twice (by passing in either "-vv" or
812           "--verbose --verbose"), the output includes comments to indicate
813           column data types and some metadata, and informational log events
814           such as row query log events if the binlog_rows_query_log_events
815           system variable is set to TRUE.
816
817           For examples that show the effect of --base64-output and --verbose
818           on row event output, see the section called “MYSQLBINLOG ROW EVENT
819           DISPLAY”.
820
821--verify-binlog-checksum, -c Verify checksums in binary log files.
822
823--version, -V Display version information and exit.
824
825           The mysqlbinlog version number shown when using this option is 3.4.
826
827--zstd-compression-level=level The compression level to use for
828           connections to the server that use the zstd compression algorithm.
829           The permitted levels are from 1 to 22, with larger values
830           indicating increasing levels of compression. The default zstd
831           compression level is 3. The compression level setting has no effect
832           on connections that do not use zstd compression.
833
834           For more information, see Section 4.2.8, “Connection Compression
835           Control”.
836
837           This option was added in MySQL 8.0.18.
838
839       You can pipe the output of mysqlbinlog into the mysql client to execute
840       the events contained in the binary log. This technique is used to
841       recover from an unexpected exit when you have an old backup (see
842       Section 7.5, “Point-in-Time (Incremental) Recovery”). For example:
843
844           mysqlbinlog binlog.000001 | mysql -u root -p
845
846       Or:
847
848           mysqlbinlog binlog.[0-9]* | mysql -u root -p
849
850       If the statements produced by mysqlbinlog may contain BLOB values,
851       these may cause problems when mysql processes them. In this case,
852       invoke mysql with the --binary-mode option.
853
854       You can also redirect the output of mysqlbinlog to a text file instead,
855       if you need to modify the statement log first (for example, to remove
856       statements that you do not want to execute for some reason). After
857       editing the file, execute the statements that it contains by using it
858       as input to the mysql program:
859
860           mysqlbinlog binlog.000001 > tmpfile
861           ... edit tmpfile ...
862           mysql -u root -p < tmpfile
863
864       When mysqlbinlog is invoked with the --start-position option, it
865       displays only those events with an offset in the binary log greater
866       than or equal to a given position (the given position must match the
867       start of one event). It also has options to stop and start when it sees
868       an event with a given date and time. This enables you to perform
869       point-in-time recovery using the --stop-datetime option (to be able to
870       say, for example, “roll forward my databases to how they were today at
871       10:30 a.m.”).
872
873       Processing multiple files. If you have more than one binary log to
874       execute on the MySQL server, the safe method is to process them all
875       using a single connection to the server. Here is an example that
876       demonstrates what may be unsafe:
877
878           mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
879           mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!
880
881       Processing binary logs this way using multiple connections to the
882       server causes problems if the first log file contains a CREATE
883       TEMPORARY TABLE statement and the second log contains a statement that
884       uses the temporary table. When the first mysql process terminates, the
885       server drops the temporary table. When the second mysql process
886       attempts to use the table, the server reports “unknown table.”
887
888       To avoid problems like this, use a single mysql process to execute the
889       contents of all binary logs that you want to process. Here is one way
890       to do so:
891
892           mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
893
894       Another approach is to write all the logs to a single file and then
895       process the file:
896
897           mysqlbinlog binlog.000001 >  /tmp/statements.sql
898           mysqlbinlog binlog.000002 >> /tmp/statements.sql
899           mysql -u root -p -e "source /tmp/statements.sql"
900
901       From MySQL 8.0.12, you can also supply multiple binary log files to
902       mysqlbinlog as streamed input using a shell pipe. An archive of
903       compressed binary log files can be decompressed and provided directly
904       to mysqlbinlog. In this example, binlog-files_1.gz contains multiple
905       binary log files for processing. The pipeline extracts the contents of
906       binlog-files_1.gz, pipes the binary log files to mysqlbinlog as
907       standard input, and pipes the output of mysqlbinlog into the mysql
908       client for execution:
909
910           gzip -cd binlog-files_1.gz | ./mysqlbinlog - | ./mysql -uroot  -p
911
912       You can specify more than one archive file, for example:
913
914           gzip -cd binlog-files_1.gz binlog-files_2.gz | ./mysqlbinlog - | ./mysql -uroot  -p
915
916       For streamed input, do not use --stop-position, because mysqlbinlog
917       cannot identify the last log file to apply this option.
918
919       LOAD DATA operations. mysqlbinlog can produce output that reproduces a
920       LOAD DATA operation without the original data file.  mysqlbinlog copies
921       the data to a temporary file and writes a LOAD DATA LOCAL statement
922       that refers to the file. The default location of the directory where
923       these files are written is system-specific. To specify a directory
924       explicitly, use the --local-load option.
925
926       Because mysqlbinlog converts LOAD DATA statements to LOAD DATA LOCAL
927       statements (that is, it adds LOCAL), both the client and the server
928       that you use to process the statements must be configured with the
929       LOCAL capability enabled. See Section 6.1.6, “Security Considerations
930       for LOAD DATA LOCAL”.
931
932           Warning
933           The temporary files created for LOAD DATA LOCAL statements are not
934           automatically deleted because they are needed until you actually
935           execute those statements. You should delete the temporary files
936           yourself after you no longer need the statement log. The files can
937           be found in the temporary file directory and have names like
938           original_file_name-#-#.
939

MYSQLBINLOG HEX DUMP FORMAT

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

MYSQLBINLOG ROW EVENT DISPLAY

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

USING MYSQLBINLOG TO BACK UP BINARY LOG FILES

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

SPECIFYING THE MYSQLBINLOG SERVER ID

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

NOTES

1463        1. MySQL Internals: The Binary Log
1464           https://dev.mysql.com/doc/internals/en/binary-log.html
1465

SEE ALSO

1467       For more information, please refer to the MySQL Reference Manual, which
1468       may already be installed locally and which is also available online at
1469       http://dev.mysql.com/doc/.
1470

AUTHOR

1472       Oracle Corporation (http://dev.mysql.com/).
1473
1474
1475
1476MySQL 8.0                         03/07/2021                    MYSQLBINLOG(1)
Impressum