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

NAME

6       mysqlbinlog - utility for processing binary log files
7

SYNOPSIS

9       mysqlbinlog [options] log_file ...
10

DESCRIPTION

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

MYSQLBINLOG HEX DUMP FORMAT

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

MYSQLBINLOG ROW EVENT DISPLAY

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

USING MYSQLBINLOG TO BACK UP BINARY LOG FILES

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

SPECIFYING THE MYSQLBINLOG SERVER ID

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

NOTES

1479        1. MySQL Internals: The Binary Log
1480           https://dev.mysql.com/doc/internals/en/binary-log.html
1481

SEE ALSO

1483       For more information, please refer to the MySQL Reference Manual, which
1484       may already be installed locally and which is also available online at
1485       http://dev.mysql.com/doc/.
1486

AUTHOR

1488       Oracle Corporation (http://dev.mysql.com/).
1489
1490
1491
1492MySQL 8.0                         08/29/2022                    MYSQLBINLOG(1)
Impressum