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

MYSQLBINLOG HEX DUMP FORMAT

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

MYSQLBINLOG ROW EVENT DISPLAY

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

USING MYSQLBINLOG TO BACK UP BINARY LOG FILES

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

SPECIFYING THE MYSQLBINLOG SERVER ID

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

NOTES

1475        1. MySQL Internals: The Binary Log
1476           https://dev.mysql.com/doc/internals/en/binary-log.html
1477

SEE ALSO

1479       For more information, please refer to the MySQL Reference Manual, which
1480       may already be installed locally and which is also available online at
1481       http://dev.mysql.com/doc/.
1482

AUTHOR

1484       Oracle Corporation (http://dev.mysql.com/).
1485
1486
1487
1488MySQL 8.0                         09/06/2019                    MYSQLBINLOG(1)
Impressum