1MYSQLBINLOG(1) MySQL Database System MYSQLBINLOG(1)
2
3
4
6 mysqlbinlog - utility for processing binary log files
7
9 mysqlbinlog [options] log_file ...
10
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 shell> 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 shell> mysqlbinlog binlog.0000003
30
31 The output includes events contained in binlog.000003. For
32 statement-based logging, event information includes the SQL statement,
33 the ID of the server on which it was executed, the timestamp when the
34 statement was executed, how much time it took, and so forth. For
35 row-based logging, the event indicates a row change rather than an SQL
36 statement. See Section 17.2.1, “Replication Formats”, for information
37 about logging modes.
38
39 Events are preceded by header comments that provide additional
40 information. For example:
41
42 # at 141
43 #100309 9:28:36 server id 123 end_log_pos 245
44 Query thread_id=3350 exec_time=11 error_code=0
45
46 In the first line, the number following at indicates the file offset,
47 or starting position, of the event in the binary log file.
48
49 The second line starts with a date and time indicating when the
50 statement started on the server where the event originated. For
51 replication, this timestamp is propagated to replica servers. server
52 id is the server_id value of the server where the event originated.
53 end_log_pos indicates where the next event starts (that is, it is the
54 end position of the current event + 1). thread_id indicates which
55 thread executed the event. exec_time is the time spent executing the
56 event, on a replication source server. On a replica, it is the
57 difference of the end execution time on the replica minus the beginning
58 execution time on the source. The difference serves as an indicator of
59 how much replication lags behind the source. error_code indicates the
60 result from executing the event. Zero means that no error occurred.
61
62 Note
63 When using event groups, the file offsets of events may be grouped
64 together and the comments of events may be grouped together. Do not
65 mistake these grouped events for blank file offsets.
66
67 The output from mysqlbinlog can be re-executed (for example, by using
68 it as input to mysql) to redo the statements in the log. This is useful
69 for recovery operations after an unexpected server exit. For other
70 usage examples, see the discussion later in this section and in
71 Section 7.5, “Point-in-Time (Incremental) Recovery”. To execute the
72 internal-use BINLOG statements used by mysqlbinlog, the user requires
73 the BINLOG_ADMIN privilege (or the deprecated SUPER privilege), or the
74 REPLICATION_APPLIER privilege plus the appropriate privileges to
75 execute each log event.
76
77 You can use mysqlbinlog to read binary log files directly and apply
78 them to the local MySQL server. You can also read binary logs from a
79 remote server by using the --read-from-remote-server option. To read
80 remote binary logs, the connection parameter options can be given to
81 indicate how to connect to the server. These options are --host,
82 --password, --port, --protocol, --socket, and --user.
83
84 When binary log files have been encrypted, which can be done from MySQL
85 8.0.14 onwards, mysqlbinlog cannot read them directly, but can read
86 them from the server using the --read-from-remote-server option. Binary
87 log files are encrypted when the server's binlog_encryption system
88 variable is set to ON. The SHOW BINARY LOGS statement shows whether a
89 particular binary log file is encrypted or unencrypted. Encrypted and
90 unencrypted binary log files can also be distinguished using the magic
91 number at the start of the file header for encrypted log files
92 (0xFD62696E), which differs from that used for unencrypted log files
93 (0xFE62696E). Note that from MySQL 8.0.14, mysqlbinlog returns a
94 suitable error if you attempt to read an encrypted binary log file
95 directly, but older versions of mysqlbinlog do not recognise the file
96 as a binary log file at all. For more information on binary log
97 encryption, see Section 17.3.2, “Encrypting Binary Log Files and Relay
98 Log Files”.
99
100 When binary log transaction payloads have been compressed, which can be
101 done from MySQL 8.0.20 onwards, mysqlbinlog versions from that release
102 on automatically decompress and decode the transaction payloads, and
103 print them as they would uncompressed events. Older versions of
104 mysqlbinlog cannot read compressed transaction payloads. When the
105 server's binlog_transaction_compression system variable is set to ON,
106 transaction payloads are compressed and then written to the server's
107 binary log file as a single event (a Transaction_payload_event). With
108 the --verbose option, mysqlbinlog adds comments stating the compression
109 algorithm used, the compressed payload size that was originally
110 received, and the resulting payload size after decompression.
111
112 Note
113 The end position (end_log_pos) that mysqlbinlog states for an
114 individual event that was part of a compressed transaction payload
115 is the same as the end position of the original compressed payload.
116 Multiple decompressed events can therefore have the same end
117 position.
118
119 mysqlbinlog's own connection compression does less if transaction
120 payloads are already compressed, but still operates on uncompressed
121 transactions and headers.
122
123 For more information on binary log transaction compression, see
124 Section 5.4.4.5, “Binary Log Transaction Compression”.
125
126 When running mysqlbinlog against a large binary log, be careful that
127 the filesystem has enough space for the resulting files. To configure
128 the directory that mysqlbinlog uses for temporary files, use the TMPDIR
129 environment variable.
130
131 mysqlbinlog sets the value of pseudo_slave_mode to true before
132 executing any SQL statements. This system variable affects the handling
133 of XA transactions, the original_commit_timestamp replication delay
134 timestamp and the original_server_version system variable, and
135 unsupported SQL modes.
136
137 mysqlbinlog supports the following options, which can be specified on
138 the command line or in the [mysqlbinlog] and [client] groups of an
139 option file. For information about option files used by MySQL programs,
140 see Section 4.2.2.2, “Using Option Files”.
141
142 · --help, -? Display a help message and exit.
143
144 · --base64-output=value This option determines when events should be
145 displayed encoded as base-64 strings using BINLOG statements. The
146 option has these permissible values (not case-sensitive):
147
148 · AUTO ("automatic") or UNSPEC ("unspecified") displays BINLOG
149 statements automatically when necessary (that is, for format
150 description events and row events). If no --base64-output
151 option is given, the effect is the same as
152 --base64-output=AUTO.
153
154 Note
155 Automatic BINLOG display is the only safe behavior if you
156 intend to use the output of mysqlbinlog to re-execute
157 binary log file contents. The other option values are
158 intended only for debugging or testing purposes because
159 they may produce output that does not include all events in
160 executable form.
161
162 · NEVER causes BINLOG statements not to be displayed.
163 mysqlbinlog exits with an error if a row event is found that
164 must be displayed using BINLOG.
165
166 · DECODE-ROWS specifies to mysqlbinlog that you intend for row
167 events to be decoded and displayed as commented SQL statements
168 by also specifying the --verbose option. Like NEVER,
169 DECODE-ROWS suppresses display of BINLOG statements, but unlike
170 NEVER, it does not exit with an error if a row event is found.
171
172 For examples that show the effect of --base64-output and --verbose
173 on row event output, see the section called “MYSQLBINLOG ROW EVENT
174 DISPLAY”.
175
176 · --bind-address=ip_address On a computer having multiple network
177 interfaces, use this option to select which interface to use for
178 connecting to the MySQL server.
179
180 · --binlog-row-event-max-size=N
181
182 ┌────────────────────┬─────────────────────────┐
183 │Command-Line Format │ --binlog-row-event-max- │
184 │ │ size=# │
185 ├────────────────────┼─────────────────────────┤
186 │Type │ Numeric │
187 ├────────────────────┼─────────────────────────┤
188 │Default Value │ 4294967040 │
189 ├────────────────────┼─────────────────────────┤
190 │Minimum Value │ 256 │
191 ├────────────────────┼─────────────────────────┤
192 │Maximum 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. file_name is interpreted relative to the current directory
330 if given as a relative path name rather than a full path name.
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 file_name is interpreted relative to the current directory if given
339 as a relative path name rather than a full path name.
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 the --defaults-group-suffix=_other option is given,
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 ffiles
423 to 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, if it exists, is read
459 in all cases. This permits passwords to be specified in a safer way
460 than on the command line even when --no-defaults is used.
461 (.mylogin.cnf is created by the mysql_config_editor utility. See
462 mysql_config_editor(1).)
463
464 For additional information about this and other option-file
465 options, see Section 4.2.2.3, “Command-Line Options that Affect
466 Option-File Handling”.
467
468 · --offset=N, -o N Skip the first N entries in the log.
469
470 · --open-files-limit=N Specify the number of open file descriptors to
471 reserve.
472
473 · --password[=password], -p[password] The password of the MySQL
474 account used for connecting to the server. The password value is
475 optional. If not given, mysqlbinlog prompts for one. If given,
476 there must be no space between --password= or -p and the password
477 following it. If no password option is specified, the default is to
478 send no password.
479
480 Specifying a password on the command line should be considered
481 insecure. To avoid giving the password on the command line, use an
482 option file. See Section 6.1.2.1, “End-User Guidelines for Password
483 Security”.
484
485 To explicitly specify that there is no password and that
486 mysqlbinlog should not prompt for one, use the --skip-password
487 option.
488
489 · --plugin-dir=dir_name The directory in which to look for plugins.
490 Specify this option if the --default-auth option is used to specify
491 an authentication plugin but mysqlbinlog does not find it. See
492 Section 6.2.17, “Pluggable Authentication”.
493
494 · --port=port_num, -P port_num The TCP/IP port number to use for
495 connecting to a remote server.
496
497 · --print-defaults Print the program name and all options that it
498 gets from option files.
499
500 For additional information about this and other option-file
501 options, see Section 4.2.2.3, “Command-Line Options that Affect
502 Option-File Handling”.
503
504 · --print-table-metadata Print table related metadata from the binary
505 log. Configure the amount of table related metadata binary logged
506 using binlog-row-metadata.
507
508 · --protocol={TCP|SOCKET|PIPE|MEMORY} The transport protocol to use
509 for connecting to the server. It is useful when the other
510 connection parameters normally result in use of a protocol other
511 than the one you want. For details on the permissible values, see
512 Section 4.2.7, “Connection Transport Protocols”.
513
514 · --raw By default, mysqlbinlog reads binary log files and writes
515 events in text format. The --raw option tells mysqlbinlog to write
516 them in their original binary format. Its use requires that
517 --read-from-remote-server also be used because the files are
518 requested from a server. mysqlbinlog writes one output file for
519 each file read from the server. The --raw option can be used to
520 make a backup of a server's binary log. With the --stop-never
521 option, the backup is “live” because mysqlbinlog stays connected to
522 the server. By default, output files are written in the current
523 directory with the same names as the original log files. Output
524 file names can be modified using the --result-file option. For more
525 information, see the section called “USING MYSQLBINLOG TO BACK UP
526 BINARY LOG FILES”.
527
528 · --read-from-remote-master=type Read binary logs from a MySQL server
529 with the COM_BINLOG_DUMP or COM_BINLOG_DUMP_GTID commands by
530 setting the option value to either BINLOG-DUMP-NON-GTIDS or
531 BINLOG-DUMP-GTIDS, respectively. If
532 --read-from-remote-master=BINLOG-DUMP-GTIDS is combined with
533 --exclude-gtids, transactions can be filtered out on the source,
534 avoiding unnecessary network traffic.
535
536 The connection parameter options are used with this option or the
537 --read-from-remote-server option. These options are --host,
538 --password, --port, --protocol, --socket, and --user. If neither of
539 the remote options is specified, the connection parameter options
540 are ignored.
541
542 The REPLICATION SLAVE privilege is required to use this option.
543
544 · --read-from-remote-server, -R Read the binary log from a MySQL
545 server rather than reading a local log file. This option requires
546 that the remote server be running. It works only for binary log
547 files on the remote server, not relay log files.
548
549 The connection parameter options are used with this option or the
550 --read-from-remote-master option. These options are --host,
551 --password, --port, --protocol, --socket, and --user. If neither of
552 the remote options is specified, the connection parameter options
553 are ignored.
554
555 The REPLICATION SLAVE privilege is required to use this option.
556
557 This option is like
558 --read-from-remote-master=BINLOG-DUMP-NON-GTIDS.
559
560 · --result-file=name, -r name Without the --raw option, this option
561 indicates the file to which mysqlbinlog writes text output. With
562 --raw, mysqlbinlog writes one binary output file for each log file
563 transferred from the server, writing them by default in the current
564 directory using the same names as the original log file. In this
565 case, the --result-file option value is treated as a prefix that
566 modifies output file names.
567
568 · --require-row-format Require row-based binary logging format for
569 events. This option enforces row-based replication events for
570 mysqlbinlog output. The stream of events produced with this option
571 would be accepted by a replication channel that is secured using
572 the REQUIRE_ROW_FORMAT option of the CHANGE MASTER TO statement.
573 binlog_format=ROW must be set on the server where the binary log
574 was written. When you specify this option, mysqlbinlog stops with
575 an error message if it encounters any events that are disallowed
576 under the REQUIRE_ROW_FORMAT restrictions, including LOAD DATA
577 INFILE instructions, creating or dropping temporary tables, INTVAR,
578 RAND, or USER_VAR events, and non-row-based events within a DML
579 transaction. mysqlbinlog also prints a SET
580 @@session.require_row_format statement at the start of its output
581 to apply the restrictions when the output is executed, and does not
582 print the SET @@session.pseudo_thread_id statement.
583
584 This option was added in MySQL 8.0.19.
585
586 · --rewrite-db='from_name->to_name' When reading from a row-based or
587 statement-based log, rewrite all occurrences of from_name to
588 to_name. Rewriting is done on the rows, for row-based logs, as well
589 as on the USE clauses, for statement-based logs.
590
591 Warning
592 Statements in which table names are qualified with database
593 names are not rewritten to use the new name when using this
594 option.
595 The rewrite rule employed as a value for this option is a string
596 having the form 'from_name->to_name', as shown previously, and for
597 this reason must be enclosed by quotation marks.
598
599 To employ multiple rewrite rules, specify the option multiple
600 times, as shown here:
601
602 shell> mysqlbinlog --rewrite-db='dbcurrent->dbold' --rewrite-db='dbtest->dbcurrent' \
603 binlog.00001 > /tmp/statements.sql
604
605 When used together with the --database option, the --rewrite-db
606 option is applied first; then --database option is applied, using
607 the rewritten database name. The order in which the options are
608 provided makes no difference in this regard.
609
610 This means that, for example, if mysqlbinlog is started with
611 --rewrite-db='mydb->yourdb' --database=yourdb, then all updates to
612 any tables in databases mydb and yourdb are included in the output.
613 On the other hand, if it is started with
614 --rewrite-db='mydb->yourdb' --database=mydb, then mysqlbinlog
615 outputs no statements at all: since all updates to mydb are first
616 rewritten as updates to yourdb before applying the --database
617 option, there remain no updates that match --database=mydb.
618
619 · --server-id=id Display only those events created by the server
620 having the given server ID.
621
622 · --server-id-bits=N Use only the first N bits of the server_id to
623 identify the server. If the binary log was written by a mysqld with
624 server-id-bits set to less than 32 and user data stored in the most
625 significant bit, running mysqlbinlog with --server-id-bits set to
626 32 enables this data to be seen.
627
628 This option is supported only by the version of mysqlbinlog
629 supplied with the NDB Cluster distribution, or built with NDB
630 Cluster support.
631
632 · --server-public-key-path=file_name The path name to a file in PEM
633 format containing a client-side copy of the public key required by
634 the server for RSA key pair-based password exchange. This option
635 applies to clients that authenticate with the sha256_password or
636 caching_sha2_password authentication plugin. This option is ignored
637 for accounts that do not authenticate with one of those plugins. It
638 is also ignored if RSA-based password exchange is not used, as is
639 the case when the client connects to the server using a secure
640 connection.
641
642 If --server-public-key-path=file_name is given and specifies a
643 valid public key file, it takes precedence over
644 --get-server-public-key.
645
646 For sha256_password, this option applies only if MySQL was built
647 using OpenSSL.
648
649 For information about the sha256_password and caching_sha2_password
650 plugins, see Section 6.4.1.3, “SHA-256 Pluggable Authentication”,
651 and Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.
652
653 · --set-charset=charset_name Add a SET NAMES charset_name statement
654 to the output to specify the character set to be used for
655 processing log files.
656
657 · --shared-memory-base-name=name On Windows, the shared-memory name
658 to use for connections made using shared memory to a local server.
659 The default value is MYSQL. The shared-memory name is
660 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 Display only the statements contained in the log,
667 without any extra information or row-based events. This is for
668 testing only, and should not be used in production systems. It is
669 deprecated, and you should expect it to be removed in a future
670 release.
671
672 · --skip-gtids[=(true|false)] Do not display any GTIDs in the output.
673 This is needed when writing to a dump file from one or more binary
674 logs containing GTIDs, as shown in this example:
675
676 shell> mysqlbinlog --skip-gtids binlog.000001 > /tmp/dump.sql
677 shell> mysqlbinlog --skip-gtids binlog.000002 >> /tmp/dump.sql
678 shell> mysql -u root -p -e "source /tmp/dump.sql"
679
680 The use of this option is otherwise not normally recommended in
681 production.
682
683 · --socket=path, -S path For connections to localhost, the Unix
684 socket file to use, or, on Windows, the name of the named pipe to
685 use.
686
687 On Windows, this option applies only if the server was started with
688 the named_pipe system variable enabled to support named-pipe
689 connections. In addition, the user making the connection must be a
690 member of the Windows group specified by the
691 named_pipe_full_access_group system variable.
692
693 · --ssl* Options that begin with --ssl specify whether to connect to
694 the server using SSL and indicate where to find SSL keys and
695 certificates. See the section called “Command Options for Encrypted
696 Connections”.
697
698 · --ssl-fips-mode={OFF|ON|STRICT} Controls whether to enable FIPS
699 mode on the client side. The --ssl-fips-mode option differs from
700 other --ssl-xxx options in that it is not used to establish
701 encrypted connections, but rather to affect which cryptographic
702 operations to permit. See Section 6.8, “FIPS Support”.
703
704 These --ssl-fips-mode values are permitted:
705
706 · OFF: Disable FIPS mode.
707
708 · ON: Enable FIPS mode.
709
710 · STRICT: Enable “strict” FIPS mode.
711
712
713 Note
714 If the OpenSSL FIPS Object Module is not available, the only
715 permitted value for --ssl-fips-mode is OFF. In this case,
716 setting --ssl-fips-mode to ON or STRICT causes the client to
717 produce a warning at startup and to operate in non-FIPS mode.
718
719 · --start-datetime=datetime Start reading the binary log at the first
720 event having a timestamp equal to or later than the datetime
721 argument. The datetime value is relative to the local time zone on
722 the machine where you run mysqlbinlog. The value should be in a
723 format accepted for the DATETIME or TIMESTAMP data types. For
724 example:
725
726 shell> mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000003
727
728 This option is useful for point-in-time recovery. See Section 7.5,
729 “Point-in-Time (Incremental) Recovery”.
730
731 · --start-position=N, -j N Start decoding the binary log at the log
732 position N, including in the output any events that begin at
733 position N or after. The position is a byte point in the log file,
734 not an event counter; it needs to point to the starting position of
735 an event to generate useful output. This option applies to the
736 first log file named on the command line.
737
738 This option is useful for point-in-time recovery. See Section 7.5,
739 “Point-in-Time (Incremental) Recovery”.
740
741 · --stop-datetime=datetime Stop reading the binary log at the first
742 event having a timestamp equal to or later than the datetime
743 argument. See the description of the --start-datetime option for
744 information about the datetime value.
745
746 This option is useful for point-in-time recovery. See Section 7.5,
747 “Point-in-Time (Incremental) Recovery”.
748
749 · --stop-never This option is used with --read-from-remote-server. It
750 tells mysqlbinlog to remain connected to the server. Otherwise
751 mysqlbinlog exits when the last log file has been transferred from
752 the server. --stop-never implies --to-last-log, so only the first
753 log file to transfer need be named on the command line.
754
755 --stop-never is commonly used with --raw to make a live binary log
756 backup, but also can be used without --raw to maintain a continuous
757 text display of log events as the server generates them.
758
759 With --stop-never, by default, mysqlbinlog reports a server ID of 1
760 when it connects to the server. Use --connection-server-id to
761 explicitly specify an alternative ID to report. It can be used to
762 avoid a conflict with the ID of a replica server or another
763 mysqlbinlog process. See the section called “SPECIFYING THE
764 MYSQLBINLOG SERVER ID”.
765
766 · --stop-never-slave-server-id=id This option is deprecated; expect
767 it to be removed in a future release. Use the
768 --connection-server-id option instead to specify a server ID for
769 mysqlbinlog to report.
770
771 · --stop-position=N Stop decoding the binary log at the log position
772 N, excluding from the output any events that begin at position N or
773 after. The position is a byte point in the log file, not an event
774 counter; it needs to point to a spot after the starting position of
775 the last event you want to include in the output. The event
776 starting before position N and finishing at or after the position
777 is the last event to be processed. This option applies to the last
778 log file named on the command line.
779
780 This option is useful for point-in-time recovery. See Section 7.5,
781 “Point-in-Time (Incremental) Recovery”.
782
783 · --tls-ciphersuites=ciphersuite_list The permissible ciphersuites
784 for encrypted connections that use TLSv1.3. The value is a list of
785 one or more colon-separated ciphersuite names. The ciphersuites
786 that can be named for this option depend on the SSL library used to
787 compile MySQL. For details, see Section 6.3.2, “Encrypted
788 Connection TLS Protocols and Ciphers”.
789
790 This option was added in MySQL 8.0.16.
791
792 · --tls-version=protocol_list The permissible TLS protocols for
793 encrypted connections. The value is a list of one or more
794 comma-separated protocol names. The protocols that can be named for
795 this option depend on the SSL library used to compile MySQL. For
796 details, see Section 6.3.2, “Encrypted Connection TLS Protocols and
797 Ciphers”.
798
799 · --to-last-log, -t Do not stop at the end of the requested binary
800 log from a MySQL server, but rather continue printing until the end
801 of the last binary log. If you send the output to the same MySQL
802 server, this may lead to an endless loop. This option requires
803 --read-from-remote-server.
804
805 · --user=user_name, -u user_name The user name of the MySQL account
806 to use when connecting to a remote server.
807
808 · --verbose, -v Reconstruct row events and display them as commented
809 SQL statements, with table partition information where applicable.
810 If this option is given twice (by passing in either "-vv" or
811 "--verbose --verbose"), the output includes comments to indicate
812 column data types and some metadata, and informational log events
813 such as row query log events if the binlog_rows_query_log_events
814 system variable is set to TRUE.
815
816 For examples that show the effect of --base64-output and --verbose
817 on row event output, see the section called “MYSQLBINLOG ROW EVENT
818 DISPLAY”.
819
820 · --verify-binlog-checksum, -c Verify checksums in binary log files.
821
822 · --version, -V Display version information and exit.
823
824 The mysqlbinlog version number shown when using this option is 3.4.
825
826 · --zstd-compression-level=level The compression level to use for
827 connections to the server that use the zstd compression algorithm.
828 The permitted levels are from 1 to 22, with larger values
829 indicating increasing levels of compression. The default zstd
830 compression level is 3. The compression level setting has no effect
831 on connections that do not use zstd compression.
832
833 For more information, see Section 4.2.8, “Connection Compression
834 Control”.
835
836 This option was added in MySQL 8.0.18.
837
838 You can pipe the output of mysqlbinlog into the mysql client to execute
839 the events contained in the binary log. This technique is used to
840 recover from an unexpected exit when you have an old backup (see
841 Section 7.5, “Point-in-Time (Incremental) Recovery”). For example:
842
843 shell> mysqlbinlog binlog.000001 | mysql -u root -p
844
845 Or:
846
847 shell> mysqlbinlog binlog.[0-9]* | mysql -u root -p
848
849 If the statements produced by mysqlbinlog may contain BLOB values,
850 these may cause problems when mysql processes them. In this case,
851 invoke mysql with the --binary-mode option.
852
853 You can also redirect the output of mysqlbinlog to a text file instead,
854 if you need to modify the statement log first (for example, to remove
855 statements that you do not want to execute for some reason). After
856 editing the file, execute the statements that it contains by using it
857 as input to the mysql program:
858
859 shell> mysqlbinlog binlog.000001 > tmpfile
860 shell> ... edit tmpfile ...
861 shell> mysql -u root -p < tmpfile
862
863 When mysqlbinlog is invoked with the --start-position option, it
864 displays only those events with an offset in the binary log greater
865 than or equal to a given position (the given position must match the
866 start of one event). It also has options to stop and start when it sees
867 an event with a given date and time. This enables you to perform
868 point-in-time recovery using the --stop-datetime option (to be able to
869 say, for example, “roll forward my databases to how they were today at
870 10:30 a.m.”).
871
872 Processing multiple files. If you have more than one binary log to
873 execute on the MySQL server, the safe method is to process them all
874 using a single connection to the server. Here is an example that
875 demonstrates what may be unsafe:
876
877 shell> mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
878 shell> mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!
879
880 Processing binary logs this way using multiple connections to the
881 server causes problems if the first log file contains a CREATE
882 TEMPORARY TABLE statement and the second log contains a statement that
883 uses the temporary table. When the first mysql process terminates, the
884 server drops the temporary table. When the second mysql process
885 attempts to use the table, the server reports “unknown table.”
886
887 To avoid problems like this, use a single mysql process to execute the
888 contents of all binary logs that you want to process. Here is one way
889 to do so:
890
891 shell> mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
892
893 Another approach is to write all the logs to a single file and then
894 process the file:
895
896 shell> mysqlbinlog binlog.000001 > /tmp/statements.sql
897 shell> mysqlbinlog binlog.000002 >> /tmp/statements.sql
898 shell> mysql -u root -p -e "source /tmp/statements.sql"
899
900 From MySQL 8.0.12, you can also supply multiple binary log files to
901 mysqlbinlog as streamed input using a shell pipe. An archive of
902 compressed binary log files can be decompressed and provided directly
903 to mysqlbinlog. In this example, binlog-files_1.gz contains multiple
904 binary log files for processing. The pipeline extracts the contents of
905 binlog-files_1.gz, pipes the binary log files to mysqlbinlog as
906 standard input, and pipes the output of mysqlbinlog into the mysql
907 client for execution:
908
909 shell> gzip -cd binlog-files_1.gz | ./mysqlbinlog - | ./mysql -uroot -p
910
911 You can specify more than one archive file, for example:
912
913 shell> gzip -cd binlog-files_1.gz binlog-files_2.gz | ./mysqlbinlog - | ./mysql -uroot -p
914
915 For streamed input, do not use --stop-position, because mysqlbinlog
916 cannot identify the last log file to apply this option.
917
918 LOAD DATA operations. mysqlbinlog can produce output that reproduces a
919 LOAD DATA operation without the original data file. mysqlbinlog copies
920 the data to a temporary file and writes a LOAD DATA LOCAL statement
921 that refers to the file. The default location of the directory where
922 these files are written is system-specific. To specify a directory
923 explicitly, use the --local-load option.
924
925 Because mysqlbinlog converts LOAD DATA statements to LOAD DATA LOCAL
926 statements (that is, it adds LOCAL), both the client and the server
927 that you use to process the statements must be configured with the
928 LOCAL capability enabled. See Section 6.1.6, “Security Considerations
929 for LOAD DATA LOCAL”.
930
931 Warning
932 The temporary files created for LOAD DATA LOCAL statements are not
933 automatically deleted because they are needed until you actually
934 execute those statements. You should delete the temporary files
935 yourself after you no longer need the statement log. The files can
936 be found in the temporary file directory and have names like
937 original_file_name-#-#.
938
940 The --hexdump option causes mysqlbinlog to produce a hex dump of the
941 binary log contents:
942
943 shell> mysqlbinlog --hexdump source-bin.000001
944
945 The hex output consists of comment lines beginning with #, so the
946 output might look like this for the preceding command:
947
948 /*!40019 SET @@SESSION.max_insert_delayed_threads=0*/;
949 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
950 # at 4
951 #051024 17:24:13 server id 1 end_log_pos 98
952 # Position Timestamp Type Master ID Size Master Pos Flags
953 # 00000004 9d fc 5c 43 0f 01 00 00 00 5e 00 00 00 62 00 00 00 00 00
954 # 00000017 04 00 35 2e 30 2e 31 35 2d 64 65 62 75 67 2d 6c |..5.0.15.debug.l|
955 # 00000027 6f 67 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |og..............|
956 # 00000037 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
957 # 00000047 00 00 00 00 9d fc 5c 43 13 38 0d 00 08 00 12 00 |.......C.8......|
958 # 00000057 04 04 04 04 12 00 00 4b 00 04 1a |.......K...|
959 # Start: binlog v 4, server v 5.0.15-debug-log created 051024 17:24:13
960 # at startup
961 ROLLBACK;
962
963 Hex dump output currently contains the elements in the following list.
964 This format is subject to change. For more information about binary log
965 format, see MySQL Internals: The Binary Log[1].
966
967 · Position: The byte position within the log file.
968
969 · Timestamp: The event timestamp. In the example shown, '9d fc 5c 43'
970 is the representation of '051024 17:24:13' in hexadecimal.
971
972 · Type: The event type code.
973
974 · Master ID: The server ID of the replication source server that
975 created the event.
976
977 · Size: The size in bytes of the event.
978
979 · Master Pos: The position of the next event in the original source's
980 binary log file.
981
982 · Flags: Event flag values.
983
985 The following examples illustrate how mysqlbinlog displays row events
986 that specify data modifications. These correspond to events with the
987 WRITE_ROWS_EVENT, UPDATE_ROWS_EVENT, and DELETE_ROWS_EVENT type codes.
988 The --base64-output=DECODE-ROWS and --verbose options may be used to
989 affect row event output.
990
991 Suppose that the server is using row-based binary logging and that you
992 execute the following sequence of statements:
993
994 CREATE TABLE t
995 (
996 id INT NOT NULL,
997 name VARCHAR(20) NOT NULL,
998 date DATE NULL
999 ) ENGINE = InnoDB;
1000 START TRANSACTION;
1001 INSERT INTO t VALUES(1, 'apple', NULL);
1002 UPDATE t SET name = 'pear', date = '2009-01-01' WHERE id = 1;
1003 DELETE FROM t WHERE id = 1;
1004 COMMIT;
1005
1006 By default, mysqlbinlog displays row events encoded as base-64 strings
1007 using BINLOG statements. Omitting extraneous lines, the output for the
1008 row events produced by the preceding statement sequence looks like
1009 this:
1010
1011 shell> mysqlbinlog log_file
1012 ...
1013 # at 218
1014 #080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
1015 BINLOG '
1016 fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1017 fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
1018 '/*!*/;
1019 ...
1020 # at 302
1021 #080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
1022 BINLOG '
1023 fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1024 fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
1025 '/*!*/;
1026 ...
1027 # at 400
1028 #080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
1029 BINLOG '
1030 fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1031 fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
1032 '/*!*/;
1033
1034 To see the row events as comments in the form of “pseudo-SQL”
1035 statements, run mysqlbinlog with the --verbose or -v option. This
1036 output level also shows table partition information where applicable.
1037 The output contains lines beginning with ###:
1038
1039 shell> mysqlbinlog -v log_file
1040 ...
1041 # at 218
1042 #080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
1043 BINLOG '
1044 fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1045 fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
1046 '/*!*/;
1047 ### INSERT INTO test.t
1048 ### SET
1049 ### @1=1
1050 ### @2='apple'
1051 ### @3=NULL
1052 ...
1053 # at 302
1054 #080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
1055 BINLOG '
1056 fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1057 fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
1058 '/*!*/;
1059 ### UPDATE test.t
1060 ### WHERE
1061 ### @1=1
1062 ### @2='apple'
1063 ### @3=NULL
1064 ### SET
1065 ### @1=1
1066 ### @2='pear'
1067 ### @3='2009:01:01'
1068 ...
1069 # at 400
1070 #080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
1071 BINLOG '
1072 fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1073 fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
1074 '/*!*/;
1075 ### DELETE FROM test.t
1076 ### WHERE
1077 ### @1=1
1078 ### @2='pear'
1079 ### @3='2009:01:01'
1080
1081 Specify --verbose or -v twice to also display data types and some
1082 metadata for each column, and informational log events such as row
1083 query log events if the binlog_rows_query_log_events system variable is
1084 set to TRUE. The output contains an additional comment following each
1085 column change:
1086
1087 shell> mysqlbinlog -vv log_file
1088 ...
1089 # at 218
1090 #080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
1091 BINLOG '
1092 fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1093 fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
1094 '/*!*/;
1095 ### INSERT INTO test.t
1096 ### SET
1097 ### @1=1 /* INT meta=0 nullable=0 is_null=0 */
1098 ### @2='apple' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
1099 ### @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
1100 ...
1101 # at 302
1102 #080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
1103 BINLOG '
1104 fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1105 fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
1106 '/*!*/;
1107 ### UPDATE test.t
1108 ### WHERE
1109 ### @1=1 /* INT meta=0 nullable=0 is_null=0 */
1110 ### @2='apple' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
1111 ### @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
1112 ### SET
1113 ### @1=1 /* INT meta=0 nullable=0 is_null=0 */
1114 ### @2='pear' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
1115 ### @3='2009:01:01' /* DATE meta=0 nullable=1 is_null=0 */
1116 ...
1117 # at 400
1118 #080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
1119 BINLOG '
1120 fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
1121 fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
1122 '/*!*/;
1123 ### DELETE FROM test.t
1124 ### WHERE
1125 ### @1=1 /* INT meta=0 nullable=0 is_null=0 */
1126 ### @2='pear' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
1127 ### @3='2009:01:01' /* DATE meta=0 nullable=1 is_null=0 */
1128
1129 You can tell mysqlbinlog to suppress the BINLOG statements for row
1130 events by using the --base64-output=DECODE-ROWS option. This is similar
1131 to --base64-output=NEVER but does not exit with an error if a row event
1132 is found. The combination of --base64-output=DECODE-ROWS and --verbose
1133 provides a convenient way to see row events only as SQL statements:
1134
1135 shell> mysqlbinlog -v --base64-output=DECODE-ROWS log_file
1136 ...
1137 # at 218
1138 #080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
1139 ### INSERT INTO test.t
1140 ### SET
1141 ### @1=1
1142 ### @2='apple'
1143 ### @3=NULL
1144 ...
1145 # at 302
1146 #080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
1147 ### UPDATE test.t
1148 ### WHERE
1149 ### @1=1
1150 ### @2='apple'
1151 ### @3=NULL
1152 ### SET
1153 ### @1=1
1154 ### @2='pear'
1155 ### @3='2009:01:01'
1156 ...
1157 # at 400
1158 #080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
1159 ### DELETE FROM test.t
1160 ### WHERE
1161 ### @1=1
1162 ### @2='pear'
1163 ### @3='2009:01:01'
1164
1165
1166 Note
1167 You should not suppress BINLOG statements if you intend to
1168 re-execute mysqlbinlog output.
1169
1170 The SQL statements produced by --verbose for row events are much more
1171 readable than the corresponding BINLOG statements. However, they do not
1172 correspond exactly to the original SQL statements that generated the
1173 events. The following limitations apply:
1174
1175 · The original column names are lost and replaced by @N, where N is a
1176 column number.
1177
1178 · Character set information is not available in the binary log, which
1179 affects string column display:
1180
1181 · There is no distinction made between corresponding binary and
1182 nonbinary string types (BINARY and CHAR, VARBINARY and VARCHAR,
1183 BLOB and TEXT). The output uses a data type of STRING for
1184 fixed-length strings and VARSTRING for variable-length strings.
1185
1186 · For multibyte character sets, the maximum number of bytes per
1187 character is not present in the binary log, so the length for
1188 string types is displayed in bytes rather than in characters.
1189 For example, STRING(4) is used as the data type for values from
1190 either of these column types:
1191
1192 CHAR(4) CHARACTER SET latin1
1193 CHAR(2) CHARACTER SET ucs2
1194
1195 · Due to the storage format for events of type UPDATE_ROWS_EVENT,
1196 UPDATE statements are displayed with the WHERE clause preceding
1197 the SET clause.
1198
1199 Proper interpretation of row events requires the information from the
1200 format description event at the beginning of the binary log. Because
1201 mysqlbinlog does not know in advance whether the rest of the log
1202 contains row events, by default it displays the format description
1203 event using a BINLOG statement in the initial part of the output.
1204
1205 If the binary log is known not to contain any events requiring a BINLOG
1206 statement (that is, no row events), the --base64-output=NEVER option
1207 can be used to prevent this header from being written.
1208
1210 By default, mysqlbinlog reads binary log files and displays their
1211 contents in text format. This enables you to examine events within the
1212 files more easily and to re-execute them (for example, by using the
1213 output as input to mysql). mysqlbinlog can read log files directly
1214 from the local file system, or, with the --read-from-remote-server
1215 option, it can connect to a server and request binary log contents from
1216 that server. mysqlbinlog writes text output to its standard output, or
1217 to the file named as the value of the --result-file=file_name option if
1218 that option is given.
1219
1220 · mysqlbinlog Backup Capabilities
1221
1222 · mysqlbinlog Backup Options
1223
1224 · Static and Live Backups
1225
1226 · Output File Naming
1227
1228 · Example: mysqldump + mysqlbinlog for Backup and Restore
1229
1230 · mysqlbinlog Backup Restrictions
1231 mysqlbinlog Backup Capabilities
1232
1233 mysqlbinlog can read binary log files and write new files containing
1234 the same content—that is, in binary format rather than text format.
1235 This capability enables you to easily back up a binary log in its
1236 original format. mysqlbinlog can make a static backup, backing up a
1237 set of log files and stopping when the end of the last file is reached.
1238 It can also make a continuous (“live”) backup, staying connected to the
1239 server when it reaches the end of the last log file and continuing to
1240 copy new events as they are generated. In continuous-backup operation,
1241 mysqlbinlog runs until the connection ends (for example, when the
1242 server exits) or mysqlbinlog is forcibly terminated. When the
1243 connection ends, mysqlbinlog does not wait and retry the connection,
1244 unlike a replica server. To continue a live backup after the server has
1245 been restarted, you must also restart mysqlbinlog.
1246
1247 Important
1248 mysqlbinlog can back up both encrypted and unencrypted binary log
1249 files . However, copies of encrypted binary log files that are
1250 generated using mysqlbinlog are stored in an unencrypted format.
1251 mysqlbinlog Backup Options
1252
1253 Binary log backup requires that you invoke mysqlbinlog with two options
1254 at minimum:
1255
1256 · The --read-from-remote-server (or -R) option tells mysqlbinlog to
1257 connect to a server and request its binary log. (This is similar to
1258 a replica server connecting to its replication source server.)
1259
1260 · The --raw option tells mysqlbinlog to write raw (binary) output,
1261 not text output.
1262
1263 Along with --read-from-remote-server, it is common to specify other
1264 options: --host indicates where the server is running, and you may also
1265 need to specify connection options such as --user and --password.
1266
1267 Several other options are useful in conjunction with --raw:
1268
1269 · --stop-never: Stay connected to the server after reaching the end
1270 of the last log file and continue to read new events.
1271
1272 · --connection-server-id=id: The server ID that mysqlbinlog reports
1273 when it connects to a server. When --stop-never is used, the
1274 default reported server ID is 1. If this causes a conflict with the
1275 ID of a replica server or another mysqlbinlog process, use
1276 --connection-server-id to specify an alternative server ID. See the
1277 section called “SPECIFYING THE MYSQLBINLOG SERVER ID”.
1278
1279 · --result-file: A prefix for output file names, as described later.
1280 Static and Live Backups
1281
1282 To back up a server's binary log files with mysqlbinlog, you must
1283 specify file names that actually exist on the server. If you do not
1284 know the names, connect to the server and use the SHOW BINARY LOGS
1285 statement to see the current names. Suppose that the statement produces
1286 this output:
1287
1288 mysql> SHOW BINARY LOGS;
1289 +---------------+-----------+-----------+
1290 | Log_name | File_size | Encrypted |
1291 +---------------+-----------+-----------+
1292 | binlog.000130 | 27459 | No |
1293 | binlog.000131 | 13719 | No |
1294 | binlog.000132 | 43268 | No |
1295 +---------------+-----------+-----------+
1296
1297 With that information, you can use mysqlbinlog to back up the binary
1298 log to the current directory as follows (enter each command on a single
1299 line):
1300
1301 · To make a static backup of binlog.000130 through binlog.000132, use
1302 either of these commands:
1303
1304 mysqlbinlog --read-from-remote-server --host=host_name --raw
1305 binlog.000130 binlog.000131 binlog.000132
1306 mysqlbinlog --read-from-remote-server --host=host_name --raw
1307 --to-last-log binlog.000130
1308
1309 The first command specifies every file name explicitly. The second
1310 names only the first file and uses --to-last-log to read through
1311 the last. A difference between these commands is that if the server
1312 happens to open binlog.000133 before mysqlbinlog reaches the end of
1313 binlog.000132, the first command does not read it, but the second
1314 command does.
1315
1316 · To make a live backup in which mysqlbinlog starts with
1317 binlog.000130 to copy existing log files, then stays connected to
1318 copy new events as the server generates them:
1319
1320 mysqlbinlog --read-from-remote-server --host=host_name --raw
1321 --stop-never binlog.000130
1322
1323 With --stop-never, it is not necessary to specify --to-last-log to
1324 read to the last log file because that option is implied.
1325 Output File Naming
1326
1327 Without --raw, mysqlbinlog produces text output and the --result-file
1328 option, if given, specifies the name of the single file to which all
1329 output is written. With --raw, mysqlbinlog writes one binary output
1330 file for each log file transferred from the server. By default,
1331 mysqlbinlog writes the files in the current directory with the same
1332 names as the original log files. To modify the output file names, use
1333 the --result-file option. In conjunction with --raw, the --result-file
1334 option value is treated as a prefix that modifies the output file
1335 names.
1336
1337 Suppose that a server currently has binary log files named
1338 binlog.000999 and up. If you use mysqlbinlog --raw to back up the
1339 files, the --result-file option produces output file names as shown in
1340 the following table. You can write the files to a specific directory by
1341 beginning the --result-file value with the directory path. If the
1342 --result-file value consists only of a directory name, the value must
1343 end with the pathname separator character. Output files are overwritten
1344 if they exist.
1345
1346 ┌─────────────────────┬────────────────────────────┐
1347 │--result-file Option │ Output File Names │
1348 ├─────────────────────┼────────────────────────────┤
1349 │--result-file=x │ xbinlog.000999 and up │
1350 ├─────────────────────┼────────────────────────────┤
1351 │--result-file=/tmp/ │ /tmp/binlog.000999 and up │
1352 ├─────────────────────┼────────────────────────────┤
1353 │--result-file=/tmp/x │ /tmp/xbinlog.000999 and up │
1354 └─────────────────────┴────────────────────────────┘
1355 Example: mysqldump + mysqlbinlog for Backup and Restore
1356
1357 The following example describes a simple scenario that shows how to use
1358 mysqldump and mysqlbinlog together to back up a server's data and
1359 binary log, and how to use the backup to restore the server if data
1360 loss occurs. The example assumes that the server is running on host
1361 host_name and its first binary log file is named binlog.000999. Enter
1362 each command on a single line.
1363
1364 Use mysqlbinlog to make a continuous backup of the binary log:
1365
1366 mysqlbinlog --read-from-remote-server --host=host_name --raw
1367 --stop-never binlog.000999
1368
1369 Use mysqldump to create a dump file as a snapshot of the server's data.
1370 Use --all-databases, --events, and --routines to back up all data, and
1371 --master-data=2 to include the current binary log coordinates in the
1372 dump file.
1373
1374 mysqldump --host=host_name --all-databases --events --routines --master-data=2> dump_file
1375
1376 Execute the mysqldump command periodically to create newer snapshots as
1377 desired.
1378
1379 If data loss occurs (for example, if the server unexpectedly exits),
1380 use the most recent dump file to restore the data:
1381
1382 mysql --host=host_name -u root -p < dump_file
1383
1384 Then use the binary log backup to re-execute events that were written
1385 after the coordinates listed in the dump file. Suppose that the
1386 coordinates in the file look like this:
1387
1388 -- CHANGE MASTER TO MASTER_LOG_FILE='binlog.001002', MASTER_LOG_POS=27284;
1389
1390 If the most recent backed-up log file is named binlog.001004,
1391 re-execute the log events like this:
1392
1393 mysqlbinlog --start-position=27284 binlog.001002 binlog.001003 binlog.001004
1394 | mysql --host=host_name -u root -p
1395
1396 You might find it easier to copy the backup files (dump file and binary
1397 log files) to the server host to make it easier to perform the restore
1398 operation, or if MySQL does not allow remote root access. mysqlbinlog
1399 Backup Restrictions
1400
1401 Binary log backups with mysqlbinlog are subject to these restrictions:
1402
1403 · mysqlbinlog does not automatically reconnect to the MySQL server if
1404 the connection is lost (for example, if a server restart occurs or
1405 there is a network outage).
1406
1407 · The delay for a backup is similar to the delay for a replica
1408 server.
1409
1411 When invoked with the --read-from-remote-server option, mysqlbinlog
1412 connects to a MySQL server, specifies a server ID to identify itself,
1413 and requests binary log files from the server. You can use mysqlbinlog
1414 to request log files from a server in several ways:
1415
1416 · Specify an explicitly named set of files: For each file,
1417 mysqlbinlog connects and issues a Binlog dump command. The server
1418 sends the file and disconnects. There is one connection per file.
1419
1420 · Specify the beginning file and --to-last-log: mysqlbinlog connects
1421 and issues a Binlog dump command for all files. The server sends
1422 all files and disconnects.
1423
1424 · Specify the beginning file and --stop-never (which implies
1425 --to-last-log): mysqlbinlog connects and issues a Binlog dump
1426 command for all files. The server sends all files, but does not
1427 disconnect after sending the last one.
1428
1429 With --read-from-remote-server only, mysqlbinlog connects using a
1430 server ID of 0, which tells the server to disconnect after sending the
1431 last requested log file.
1432
1433 With --read-from-remote-server and --stop-never, mysqlbinlog connects
1434 using a nonzero server ID, so the server does not disconnect after
1435 sending the last log file. The server ID is 1 by default, but this can
1436 be changed with --connection-server-id.
1437
1438 Thus, for the first two ways of requesting files, the server
1439 disconnects because mysqlbinlog specifies a server ID of 0. It does not
1440 disconnect if --stop-never is given because mysqlbinlog specifies a
1441 nonzero server ID.
1442
1444 Copyright © 1997, 2020, Oracle and/or its affiliates.
1445
1446 This documentation is free software; you can redistribute it and/or
1447 modify it only under the terms of the GNU General Public License as
1448 published by the Free Software Foundation; version 2 of the License.
1449
1450 This documentation is distributed in the hope that it will be useful,
1451 but WITHOUT ANY WARRANTY; without even the implied warranty of
1452 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1453 General Public License for more details.
1454
1455 You should have received a copy of the GNU General Public License along
1456 with the program; if not, write to the Free Software Foundation, Inc.,
1457 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see
1458 http://www.gnu.org/licenses/.
1459
1460
1462 1. MySQL Internals: The Binary Log
1463 https://dev.mysql.com/doc/internals/en/binary-log.html
1464
1466 For more information, please refer to the MySQL Reference Manual, which
1467 may already be installed locally and which is also available online at
1468 http://dev.mysql.com/doc/.
1469
1471 Oracle Corporation (http://dev.mysql.com/).
1472
1473
1474
1475MySQL 8.0 11/26/2020 MYSQLBINLOG(1)