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