1MARIADB-BINLOG(1) MariaDB Database System MARIADB-BINLOG(1)
2
3
4
6 mariadb-binlog - utility for processing binary log files (mysqlbinlog
7 is now a symlink to mariadb-binlog)
8
10 mysqlbinlog [options] log_file ...
11
13 The server´s binary log consists of files containing “events” that
14 describe modifications to database contents. The server writes these
15 files in binary format. To display their contents in text format, use
16 the mysqlbinlog utility. You can also use mysqlbinlog to display the
17 contents of relay log files written by a slave server in a replication
18 setup because relay logs have the same format as binary logs.
19
20 Invoke mysqlbinlog like this:
21
22 shell> mysqlbinlog [options] log_file ...
23
24 For example, to display the contents of the binary log file named
25 binlog.000003, use this command:
26
27 shell> mysqlbinlog binlog.0000003
28
29 The output includes events contained in binlog.000003. For
30 statement-based logging, event information includes the SQL statement,
31 the ID of the server on which it was executed, the timestamp when the
32 statement was executed, how much time it took, and so forth. For
33 row-based logging, the event indicates a row change rather than an SQL
34 statement.
35
36 Events are preceded by header comments that provide additional
37 information. For example:
38
39 # at 141
40 #100309 9:28:36 server id 123 end_log_pos 245
41 Query thread_id=3350 exec_time=11 error_code=0
42
43 In the first line, the number following at indicates the starting
44 position of the event in the binary log file.
45
46 The second line starts with a date and time indicating when the
47 statement started on the server where the event originated. For
48 replication, this timestamp is propagated to slave servers. server id
49 is the server_id value of the server where the event originated.
50 end_log_pos indicates where the next event starts (that is, it is the
51 end position of the current event + 1). thread_id indicates which
52 thread executed the event. exec_time is the time spent executing the
53 event, on a master server. On a slave, it is the difference of the end
54 execution time on the slave minus the beginning execution time on the
55 master. The difference serves as an indicator of how much replication
56 lags behind the master. error_code indicates the result from executing
57 the event. Zero means that no error occurred.
58
59 The output from mysqlbinlog can be re-executed (for example, by using
60 it as input to mysql) to redo the statements in the log. This is useful
61 for recovery operations after a server crash. For other usage examples,
62 see the discussion later in this section.
63
64 Normally, you use mysqlbinlog to read binary log files directly and
65 apply them to the local MariaDB server. It is also possible to read
66 binary logs from a remote server by using the --read-from-remote-server
67 option. To read remote binary logs, the connection parameter options
68 can be given to indicate how to connect to the server. These options
69 are --host, --password, --port, --protocol, --socket, and --user; they
70 are ignored except when you also use the --read-from-remote-server
71 option.
72
73 mysqlbinlog supports the following options, which can be specified on
74 the command line or in the [mysqlbinlog] and [client] option file
75 groups.
76
77 • --help, -?
78
79 Display a help message and exit.
80
81 • --base64-output=value
82
83 This option determines when events should be displayed encoded as
84 base-64 strings using BINLOG statements. The option has these
85 allowable values (not case sensitive):
86
87 • AUTO ("automatic") or UNSPEC ("unspecified") displays BINLOG
88 statements automatically when necessary (that is, for format
89 description events and row events). This is the default if no
90 --base64-output option is given.
91
92 Note
93 Automatic BINLOG display is the only safe behavior if you
94 intend to use the output of mysqlbinlog to re-execute
95 binary log file contents. The other option values are
96 intended only for debugging or testing purposes because
97 they may produce output that does not include all events in
98 executable form.
99
100 • NEVER causes BINLOG statements not to be displayed.
101 mysqlbinlog exits with an error if a row event is found that
102 must be displayed using BINLOG.
103
104 • DECODE-ROWS specifies to mysqlbinlog that you intend for row
105 events to be decoded and displayed as commented SQL statements
106 by also specifying the --verbose option. Like NEVER,
107 DECODE-ROWS suppresses display of BINLOG statements, but unlike
108 NEVER, it does not exit with an error if a row event is found.
109 The --base64-output can be given as --base64-output or
110 --skip-base64-output (with the sense of AUTO or NEVER).
111
112 For examples that show the effect of --base64-output and
113 --verbose on row event output, see the section called
114 “MYSQLBINLOG ROW EVENT DISPLAY”.
115
116 • --binlog-row-event-max-size=path
117
118 The directory where character sets are installed.
119
120 • --character-sets-dir=path
121
122 The directory where character sets are installed.
123
124 • --database=db_name, -d db_name
125
126 This option causes mysqlbinlog to output entries from the binary
127 log (local log only) that occur while db_name has been selected as
128 the default database by USE.
129
130 The --database option for mysqlbinlog is similar to the
131 --binlog-do-db option for mysqld, but can be used to specify only
132 one database. If --database is given multiple times, only the last
133 instance is used.
134
135 The effects of this option depend on whether the statement-based or
136 row-based logging format is in use, in the same way that the
137 effects of --binlog-do-db depend on whether statement-based or
138 row-based logging is in use.
139
140 Statement-based logging. The --database option works as follows:
141
142 • While db_name is the default database, statements are output
143 whether they modify tables in db_name or a different database.
144
145 • Unless db_name is selected as the default database, statements
146 are not output, even if they modify tables in db_name.
147
148 • There is an exception for CREATE DATABASE, ALTER DATABASE, and
149 DROP DATABASE. The database being created, altered, or dropped
150 is considered to be the default database when determining
151 whether to output the statement.
152 Suppose that the binary log was created by executing these
153 statements using statement-based-logging:
154
155 INSERT INTO test.t1 (i) VALUES(100);
156 INSERT INTO db2.t2 (j) VALUES(200);
157 USE test;
158 INSERT INTO test.t1 (i) VALUES(101);
159 INSERT INTO t1 (i) VALUES(102);
160 INSERT INTO db2.t2 (j) VALUES(201);
161 USE db2;
162 INSERT INTO test.t1 (i) VALUES(103);
163 INSERT INTO db2.t2 (j) VALUES(202);
164 INSERT INTO t2 (j) VALUES(203);
165
166 mysqlbinlog --database=test does not output the first two
167 INSERT statements because there is no default database. It
168 outputs the three INSERT statements following USE test, but not
169 the three INSERT statements following USE db2.
170
171 mysqlbinlog --database=db2 does not output the first two INSERT
172 statements because there is no default database. It does not
173 output the three INSERT statements following USE test, but does
174 output the three INSERT statements following USE db2.
175
176 Row-based logging. mysqlbinlog outputs only entries that
177 change tables belonging to db_name. The default database has no
178 effect on this. Suppose that the binary log just described was
179 created using row-based logging rather than statement-based
180 logging. mysqlbinlog --database=test outputs only those
181 entries that modify t1 in the test database, regardless of
182 whether USE was issued or what the default database is. If a
183 server is running with binlog_format set to MIXED and you want
184 it to be possible to use mysqlbinlog with the --database
185 option, you must ensure that tables that are modified are in
186 the database selected by USE. (In particular, no cross-database
187 updates should be used.)
188
189 Note
190 This option did not work correctly for mysqlbinlog with
191 row-based logging prior to MySQL 5.1.37.
192
193 • --debug[=debug_options], -# [debug_options]
194
195 Write a debugging log. A typical debug_options string is
196 ´d:t:o,file_name´. The default is ´d:t:o,/tmp/mysqlbinlog.trace´.
197
198 • --debug-check
199
200 Print some debugging information when the program exits.
201
202 • --debug-info
203
204 Print debugging information and memory and CPU usage statistics
205 when the program exits.
206
207 • --defaults-extra-file=name
208
209 Read this file after the global files are read.
210
211 • --defaults-file=name
212
213 Only read default options from the given file.
214
215 • --default-auth=name
216
217 Default authentication client-side plugin to use.
218
219 • --disable-log-bin, -D
220
221 Disable binary logging. This is useful for avoiding an endless loop
222 if you use the --to-last-log option and are sending the output to
223 the same MariaDB server. This option also is useful when restoring
224 after a crash to avoid duplication of the statements you have
225 logged.
226
227 This option requires that you have the SUPER privilege. It causes
228 mysqlbinlog to include a SET sql_log_bin = 0 statement in its
229 output to disable binary logging of the remaining output. The SET
230 statement is ineffective unless you have the SUPER privilege.
231
232 • --force-if-open
233
234 Force if binlog was not closed properly. Defaults to on; use
235 --skip-force-if-open to disable.
236
237 • --force-read, -f
238
239 With this option, if mysqlbinlog reads a binary log event that it
240 does not recognize, it prints a warning, ignores the event, and
241 continues. Without this option, mysqlbinlog stops if it reads such
242 an event.
243
244 • --hexdump, -H
245
246 Display a hex dump of the log in comments, as described in the
247 section called “MYSQLBINLOG HEX DUMP FORMAT”. The hex output can be
248 helpful for replication debugging.
249
250 • --host=host_name, -h host_name
251
252 Get the binary log from the MariaDB server on the given host.
253
254 • --local-load=path, -l path
255
256 Prepare local temporary files for LOAD DATA INFILE in the specified
257 directory.
258
259 • --no-defaults
260
261 Don't read default options from any option file.
262
263 • --offset=N, -o N
264
265 Skip the first N entries in the log.
266
267 • --open-files-limit=NUM
268
269 Sets the open_files_limit variable, which is used to reserve file
270 descriptors for mysqlbinlog.
271
272 • --password[=password], -p[password]
273
274 The password to use when connecting to the server. If you use the
275 short option form (-p), you cannot have a space between the option
276 and the password. If you omit the password value following the
277 --password or -p option on the command line, mysqlbinlog prompts
278 for one.
279
280 Specifying a password on the command line should be considered
281 insecure. You can use an option file to avoid giving the password
282 on the command line.
283
284 • --plugin-dir=dir_name
285
286 Directory for client-side plugins.
287
288 • --print-defaults
289
290 Print the program argument list from all option files and exit.
291
292 • --port=port_num, -P port_num
293
294 The TCP/IP port number to use for connecting to a remote server, or
295 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT,
296 /etc/services, built-in default (3306).
297
298 • --protocol={TCP|SOCKET|PIPE|MEMORY}
299
300 The connection protocol to use for connecting to the server. It is
301 useful when the other connection parameters normally would cause a
302 protocol to be used other than the one you want.
303
304 • --raw
305
306 Requires -R. Output raw binlog data instead of SQL statements.
307 Output files named after server logs.
308
309 • --read-from-remote-server, -R
310
311 Read the binary log from a MariaDB server rather than reading a
312 local log file. Any connection parameter options are ignored unless
313 this option is given as well. These options are --host, --password,
314 --port, --protocol, --socket, and --user.
315
316 This option requires that the remote server be running. It works
317 only for binary log files on the remote server, not relay log
318 files.
319
320 • --result-file=name, -r name
321
322 Direct output to the given file. With --raw this is a prefix for
323 the file names.
324
325 • --rewrite-db=name, -r name
326
327 Updates to a database with a different name than the original.
328 Example: rewrite-db='from->to'. For events that are binlogged as
329 statements, rewriting the database constitutes changing a
330 statement's default database from db1 to db2. There is no statement
331 analysis or rewrite of any kind, that is, if one specifies
332 "db1.tbl" in the statement explicitly, that occurrence won't be
333 changed to "db2.tbl". Row-based events are rewritten correctly to
334 use the new database name. Filtering (e.g. with --database=name)
335 happens after the database rewrites have been performed. If you use
336 this option on the command line and ">" has a special meaning to
337 your command interpreter, quote the value (e.g. --rewrite-
338 db="oldname->newname".
339
340 • --server-id=id
341
342 Display only those events created by the server having the given
343 server ID.
344
345 • --set-charset=charset_name
346
347 Add a SET NAMES charset_name statement to the output to specify the
348 character set to be used for processing log files.
349
350 • --short-form, -s
351
352 Display only the statements contained in the log, no extra info and
353 no row-based events. This is for testing only, and should not be
354 used in production systems. If you want to suppress base64-output,
355 consider using --base64-output=never instead.
356
357 • --socket=path, -S path
358
359 For connections to localhost, the Unix socket file to use, or, on
360 Windows, the name of the named pipe to use.
361
362 • --start-datetime=datetime
363
364 Start reading the binary log at the first event having a timestamp
365 equal to or later than the datetime argument. The datetime value is
366 relative to the local time zone on the machine where you run
367 mysqlbinlog. The value should be in a format accepted for the
368 DATETIME or TIMESTAMP data types. For example:
369
370 shell> mysqlbinlog --start-datetime="2014-12-25 11:25:56" binlog.000003
371
372 This option is useful for point-in-time recovery.
373
374 • --start-position=N, -j N
375
376 Start reading the binary log at the first event having a position
377 equal to or greater than N. This option applies to the first log
378 file named on the command line.
379
380 This option is useful for point-in-time recovery.
381
382 • --stop-datetime=datetime
383
384 Stop reading the binary log at the first event having a timestamp
385 equal to or later than the datetime argument. This option is useful
386 for point-in-time recovery. See the description of the
387 --start-datetime option for information about the datetime value.
388
389 This option is useful for point-in-time recovery.
390
391 • --stop-never
392
393 Wait for more data from the server instead of stopping at the end
394 of the last log. Implies --to-last-log.
395
396 • --stop-never-slave-server-id
397
398 The slave server_id used for --read-from-remote-server --stop-
399 never.
400
401 • --stop-position=N
402
403 Stop reading the binary log at the first event having a position
404 equal to or greater than N. This option applies to the last log
405 file named on the command line.
406
407 This option is useful for point-in-time recovery.
408
409 • --table, -T
410
411 List entries for just this table (local log only).
412
413 • --to-last-log, -t
414
415 Do not stop at the end of the requested binary log from a MariaDB
416 server, but rather continue printing until the end of the last
417 binary log. If you send the output to the same MariaDB server, this
418 may lead to an endless loop, so this option requires
419 --read-from-remote-server.
420
421 • --user=user_name, -u user_name
422
423 The MariaDB username to use when connecting to a remote server.
424
425 • --verbose, -v
426
427 Reconstruct row events and display them as commented SQL
428 statements. If this option is given twice, the output includes
429 comments to indicate column data types and some metadata.
430
431 For examples that show the effect of --base64-output and --verbose
432 on row event output, see the section called “MYSQLBINLOG ROW EVENT
433 DISPLAY”.
434
435 • --version, -V
436
437 Display version information and exit.
438
439 You can also set the following variable by using --var_name=value
440 syntax:
441
442 • open_files_limit
443
444 Specify the number of open file descriptors to reserve.
445
446 You can pipe the output of mysqlbinlog into the mysql client to execute
447 the events contained in the binary log. This technique is used to
448 recover from a crash when you have an old backup. For example:
449
450 shell> mysqlbinlog binlog.000001 | mysql -u root -p
451
452 Or:
453
454 shell> mysqlbinlog binlog.[0-9]* | mysql -u root -p
455
456 You can also redirect the output of mysqlbinlog to a text file instead,
457 if you need to modify the statement log first (for example, to remove
458 statements that you do not want to execute for some reason). After
459 editing the file, execute the statements that it contains by using it
460 as input to the mysql program:
461
462 shell> mysqlbinlog binlog.000001 > tmpfile
463 shell> ... edit tmpfile ...
464 shell> mysql -u root -p < tmpfile
465
466 When mysqlbinlog is invoked with the --start-position option, it
467 displays only those events with an offset in the binary log greater
468 than or equal to a given position (the given position must match the
469 start of one event). It also has options to stop and start when it sees
470 an event with a given date and time. This enables you to perform
471 point-in-time recovery using the --stop-datetime option (to be able to
472 say, for example, “roll forward my databases to how they were today at
473 10:30 a.m.”).
474
475 If you have more than one binary log to execute on the MariaDB server,
476 the safe method is to process them all using a single connection to the
477 server. Here is an example that demonstrates what may be unsafe:
478
479 shell> mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
480 shell> mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!
481
482 Processing binary logs this way using different connections to the
483 server causes problems if the first log file contains a CREATE
484 TEMPORARY TABLE statement and the second log contains a statement that
485 uses the temporary table. When the first mysql process terminates, the
486 server drops the temporary table. When the second mysql process
487 attempts to use the table, the server reports “unknown table.”
488
489 To avoid problems like this, use a single mysql process to execute the
490 contents of all binary logs that you want to process. Here is one way
491 to do so:
492
493 shell> mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
494
495 Another approach is to write all the logs to a single file and then
496 process the file:
497
498 shell> mysqlbinlog binlog.000001 > /tmp/statements.sql
499 shell> mysqlbinlog binlog.000002 >> /tmp/statements.sql
500 shell> mysql -u root -p -e "source /tmp/statements.sql"
501
502 mysqlbinlog can produce output that reproduces a LOAD DATA INFILE
503 operation without the original data file. mysqlbinlog copies the data
504 to a temporary file and writes a LOAD DATA LOCAL INFILE statement that
505 refers to the file. The default location of the directory where these
506 files are written is system-specific. To specify a directory
507 explicitly, use the --local-load option.
508
509 Because mysqlbinlog converts LOAD DATA INFILE statements to LOAD DATA
510 LOCAL INFILE statements (that is, it adds LOCAL), both the client and
511 the server that you use to process the statements must be configured
512 with the LOCAL capability enabled.
513
514 Warning
515 The temporary files created for LOAD DATA LOCAL statements are not
516 automatically deleted because they are needed until you actually
517 execute those statements. You should delete the temporary files
518 yourself after you no longer need the statement log. The files can
519 be found in the temporary file directory and have names like
520 original_file_name-#-#.
521
523 The --hexdump option causes mysqlbinlog to produce a hex dump of the
524 binary log contents:
525
526 shell> mysqlbinlog --hexdump master-bin.000001
527
528 The hex output consists of comment lines beginning with #, so the
529 output might look like this for the preceding command:
530
531 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
532 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
533 # at 4
534 #051024 17:24:13 server id 1 end_log_pos 98
535 # Position Timestamp Type Master ID Size Master Pos Flags
536 # 00000004 9d fc 5c 43 0f 01 00 00 00 5e 00 00 00 62 00 00 00 00 00
537 # 00000017 04 00 35 2e 30 2e 31 35 2d 64 65 62 75 67 2d 6c |..5.0.15.debug.l|
538 # 00000027 6f 67 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |og..............|
539 # 00000037 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
540 # 00000047 00 00 00 00 9d fc 5c 43 13 38 0d 00 08 00 12 00 |.......C.8......|
541 # 00000057 04 04 04 04 12 00 00 4b 00 04 1a |.......K...|
542 # Start: binlog v 4, server v 5.0.15-debug-log created 051024 17:24:13
543 # at startup
544 ROLLBACK;
545
546 Hex dump output currently contains the elements in the following list.
547 This format is subject to change. (For more information about binary
548 log format, see
549 http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log.)
550
551 • Position: The byte position within the log file.
552
553 • Timestamp: The event timestamp. In the example shown, ´9d fc 5c 43´
554 is the representation of ´051024 17:24:13´ in hexadecimal.
555
556 • Type: The event type code. In the example shown, ´0f´ indicates a
557 FORMAT_DESCRIPTION_EVENT. The following table lists the possible
558 type codes.
559
560 ┌─────┬──────────────────────────┬─────────────────────────────────┐
561 │Type │ Name │ Meaning │
562 ├─────┼──────────────────────────┼─────────────────────────────────┤
563 │00 │ UNKNOWN_EVENT │ This event should never be │
564 │ │ │ present in the log. │
565 ├─────┼──────────────────────────┼─────────────────────────────────┤
566 │01 │ START_EVENT_V3 │ This indicates the start of a │
567 │ │ │ log file written by MySQL 4 or │
568 │ │ │ earlier. │
569 ├─────┼──────────────────────────┼─────────────────────────────────┤
570 │02 │ QUERY_EVENT │ The most common type of events. │
571 │ │ │ These contain statements │
572 │ │ │ executed on the master. │
573 ├─────┼──────────────────────────┼─────────────────────────────────┤
574 │03 │ STOP_EVENT │ Indicates that master has │
575 │ │ │ stopped. │
576 ├─────┼──────────────────────────┼─────────────────────────────────┤
577 │04 │ ROTATE_EVENT │ Written when the master │
578 │ │ │ switches to a new log file. │
579 ├─────┼──────────────────────────┼─────────────────────────────────┤
580 │05 │ INTVAR_EVENT │ Used for AUTO_INCREMENT values │
581 │ │ │ or when the LAST_INSERT_ID() │
582 │ │ │ function is used in the │
583 │ │ │ statement. │
584 ├─────┼──────────────────────────┼─────────────────────────────────┤
585 │06 │ LOAD_EVENT │ Used for LOAD DATA INFILE in │
586 │ │ │ MySQL 3.23. │
587 ├─────┼──────────────────────────┼─────────────────────────────────┤
588 │07 │ SLAVE_EVENT │ Reserved for future use. │
589 ├─────┼──────────────────────────┼─────────────────────────────────┤
590 │08 │ CREATE_FILE_EVENT │ Used for LOAD DATA INFILE │
591 │ │ │ statements. This indicates the │
592 │ │ │ start of execution of such a │
593 │ │ │ statement. A temporary file is │
594 │ │ │ created on the slave. Used in │
595 │ │ │ MySQL 4 only. │
596 ├─────┼──────────────────────────┼─────────────────────────────────┤
597 │09 │ APPEND_BLOCK_EVENT │ Contains data for use in a LOAD │
598 │ │ │ DATA INFILE statement. The data │
599 │ │ │ is stored in the temporary file │
600 │ │ │ on the slave. │
601 ├─────┼──────────────────────────┼─────────────────────────────────┤
602 │0a │ EXEC_LOAD_EVENT │ Used for LOAD DATA INFILE │
603 │ │ │ statements. The contents of the │
604 │ │ │ temporary file is stored in the │
605 │ │ │ table on the slave. Used in │
606 │ │ │ MySQL 4 only. │
607 ├─────┼──────────────────────────┼─────────────────────────────────┤
608 │0b │ DELETE_FILE_EVENT │ Rollback of a LOAD DATA INFILE │
609 │ │ │ statement. The temporary file │
610 │ │ │ should be deleted on the slave. │
611 ├─────┼──────────────────────────┼─────────────────────────────────┤
612 │0c │ NEW_LOAD_EVENT │ Used for LOAD DATA INFILE in │
613 │ │ │ MySQL 4 and earlier. │
614 ├─────┼──────────────────────────┼─────────────────────────────────┤
615 │0d │ RAND_EVENT │ Used to send information about │
616 │ │ │ random values if the RAND() │
617 │ │ │ function is used in the │
618 │ │ │ statement. │
619 ├─────┼──────────────────────────┼─────────────────────────────────┤
620 │0e │ USER_VAR_EVENT │ Used to replicate user │
621 │ │ │ variables. │
622 ├─────┼──────────────────────────┼─────────────────────────────────┤
623 │0f │ FORMAT_DESCRIPTION_EVENT │ This indicates the start of a │
624 │ │ │ log file written by MySQL 5 or │
625 │ │ │ later. │
626 ├─────┼──────────────────────────┼─────────────────────────────────┤
627 │10 │ XID_EVENT │ Event indicating commit of an │
628 │ │ │ XA transaction. │
629 ├─────┼──────────────────────────┼─────────────────────────────────┤
630 │11 │ BEGIN_LOAD_QUERY_EVENT │ Used for LOAD DATA INFILE │
631 │ │ │ statements in MySQL 5 and │
632 │ │ │ later. │
633 ├─────┼──────────────────────────┼─────────────────────────────────┤
634 │12 │ EXECUTE_LOAD_QUERY_EVENT │ Used for LOAD DATA INFILE │
635 │ │ │ statements in MySQL 5 and │
636 │ │ │ later. │
637 ├─────┼──────────────────────────┼─────────────────────────────────┤
638 │13 │ TABLE_MAP_EVENT │ Information about a table │
639 │ │ │ definition. Used in MySQL 5.1.5 │
640 │ │ │ and later. │
641 ├─────┼──────────────────────────┼─────────────────────────────────┤
642 │14 │ PRE_GA_WRITE_ROWS_EVENT │ Row data for a single table │
643 │ │ │ that should be created. Used in │
644 │ │ │ MySQL 5.1.5 to 5.1.17. │
645 ├─────┼──────────────────────────┼─────────────────────────────────┤
646 │15 │ PRE_GA_UPDATE_ROWS_EVENT │ Row data for a single table │
647 │ │ │ that needs to be updated. Used │
648 │ │ │ in MySQL 5.1.5 to 5.1.17. │
649 ├─────┼──────────────────────────┼─────────────────────────────────┤
650 │16 │ PRE_GA_DELETE_ROWS_EVENT │ Row data for a single table │
651 │ │ │ that should be deleted. Used in │
652 │ │ │ MySQL 5.1.5 to 5.1.17. │
653 ├─────┼──────────────────────────┼─────────────────────────────────┤
654 │17 │ WRITE_ROWS_EVENT │ Row data for a single table │
655 │ │ │ that should be created. Used in │
656 │ │ │ MySQL 5.1.18 and later. │
657 ├─────┼──────────────────────────┼─────────────────────────────────┤
658 │18 │ UPDATE_ROWS_EVENT │ Row data for a single table │
659 │ │ │ that needs to be updated. Used │
660 │ │ │ in MySQL 5.1.18 and later. │
661 ├─────┼──────────────────────────┼─────────────────────────────────┤
662 │19 │ DELETE_ROWS_EVENT │ Row data for a single table │
663 │ │ │ that should be deleted. Used in │
664 │ │ │ MySQL 5.1.18 and later. │
665 ├─────┼──────────────────────────┼─────────────────────────────────┤
666 │1a │ INCIDENT_EVENT │ Something out of the ordinary │
667 │ │ │ happened. Added in MySQL │
668 │ │ │ 5.1.18. │
669 └─────┴──────────────────────────┴─────────────────────────────────┘
670
671 • Master ID: The server ID of the master that created the event.
672
673 • Size: The size in bytes of the event.
674
675 • Master Pos: The position of the next event in the original master
676 log file.
677
678 • Flags: 16 flags. Currently, the following flags are used. The
679 others are reserved for future use.
680
681 ┌─────┬─────────────────────────────┬──────────────────────────────┐
682 │Flag │ Name │ Meaning │
683 ├─────┼─────────────────────────────┼──────────────────────────────┤
684 │01 │ LOG_EVENT_BINLOG_IN_USE_F │ Log file correctly closed. │
685 │ │ │ (Used only in │
686 │ │ │ FORMAT_DESCRIPTION_EVENT.) │
687 │ │ │ If this flag is set (if the │
688 │ │ │ flags are, for example, ´01 │
689 │ │ │ 00´) in a │
690 │ │ │ FORMAT_DESCRIPTION_EVENT, │
691 │ │ │ the log file has not been │
692 │ │ │ properly closed. Most │
693 │ │ │ probably this is because of │
694 │ │ │ a master crash (for example, │
695 │ │ │ due to power failure). │
696 ├─────┼─────────────────────────────┼──────────────────────────────┤
697 │02 │ │ Reserved for future use. │
698 ├─────┼─────────────────────────────┼──────────────────────────────┤
699 │04 │ LOG_EVENT_THREAD_SPECIFIC_F │ Set if the event is │
700 │ │ │ dependent on the connection │
701 │ │ │ it was executed in (for │
702 │ │ │ example, ´04 00´), for │
703 │ │ │ example, if the event uses │
704 │ │ │ temporary tables. │
705 ├─────┼─────────────────────────────┼──────────────────────────────┤
706 │08 │ LOG_EVENT_SUPPRESS_USE_F │ Set in some circumstances │
707 │ │ │ when the event is not │
708 │ │ │ dependent on the default │
709 │ │ │ database. │
710 └─────┴─────────────────────────────┴──────────────────────────────┘
711
713 The following examples illustrate how mysqlbinlog displays row events
714 that specify data modifications. These correspond to events with the
715 WRITE_ROWS_EVENT, UPDATE_ROWS_EVENT, and DELETE_ROWS_EVENT type codes.
716 The --base64-output=DECODE-ROWS and --verbose options may be used to
717 affect row event output.
718
719 Suppose that the server is using row-based binary logging and that you
720 execute the following sequence of statements:
721
722 CREATE TABLE t
723 (
724 id INT NOT NULL,
725 name VARCHAR(20) NOT NULL,
726 date DATE NULL
727 ) ENGINE = InnoDB;
728 START TRANSACTION;
729 INSERT INTO t VALUES(1, ´apple´, NULL);
730 UPDATE t SET name = ´pear´, date = ´2009-01-01´ WHERE id = 1;
731 DELETE FROM t WHERE id = 1;
732 COMMIT;
733
734 By default, mysqlbinlog displays row events encoded as base-64 strings
735 using BINLOG statements. Omitting extraneous lines, the output for the
736 row events produced by the preceding statement sequence looks like
737 this:
738
739 shell> mysqlbinlog log_file
740 ...
741 # at 218
742 #080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
743 BINLOG ´
744 fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
745 fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
746 ´/*!*/;
747 ...
748 # at 302
749 #080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
750 BINLOG ´
751 fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
752 fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
753 ´/*!*/;
754 ...
755 # at 400
756 #080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
757 BINLOG ´
758 fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
759 fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
760 ´/*!*/;
761
762 To see the row events as comments in the form of “pseudo-SQL”
763 statements, run mysqlbinlog with the --verbose or -v option. The output
764 will contain lines beginning with ###:
765
766 shell> mysqlbinlog -v log_file
767 ...
768 # at 218
769 #080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
770 BINLOG ´
771 fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
772 fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
773 ´/*!*/;
774 ### INSERT INTO test.t
775 ### SET
776 ### @1=1
777 ### @2=´apple´
778 ### @3=NULL
779 ...
780 # at 302
781 #080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
782 BINLOG ´
783 fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
784 fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
785 ´/*!*/;
786 ### UPDATE test.t
787 ### WHERE
788 ### @1=1
789 ### @2=´apple´
790 ### @3=NULL
791 ### SET
792 ### @1=1
793 ### @2=´pear´
794 ### @3=´2009:01:01´
795 ...
796 # at 400
797 #080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
798 BINLOG ´
799 fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
800 fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
801 ´/*!*/;
802 ### DELETE FROM test.t
803 ### WHERE
804 ### @1=1
805 ### @2=´pear´
806 ### @3=´2009:01:01´
807
808 Specify --verbose or -v twice to also display data types and some
809 metadata for each column. The output will contain an additional comment
810 following each column change:
811
812 shell> mysqlbinlog -vv log_file
813 ...
814 # at 218
815 #080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
816 BINLOG ´
817 fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
818 fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
819 ´/*!*/;
820 ### INSERT INTO test.t
821 ### SET
822 ### @1=1 /* INT meta=0 nullable=0 is_null=0 */
823 ### @2=´apple´ /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
824 ### @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
825 ...
826 # at 302
827 #080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
828 BINLOG ´
829 fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
830 fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
831 ´/*!*/;
832 ### UPDATE test.t
833 ### WHERE
834 ### @1=1 /* INT meta=0 nullable=0 is_null=0 */
835 ### @2=´apple´ /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
836 ### @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
837 ### SET
838 ### @1=1 /* INT meta=0 nullable=0 is_null=0 */
839 ### @2=´pear´ /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
840 ### @3=´2009:01:01´ /* DATE meta=0 nullable=1 is_null=0 */
841 ...
842 # at 400
843 #080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
844 BINLOG ´
845 fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
846 fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
847 ´/*!*/;
848 ### DELETE FROM test.t
849 ### WHERE
850 ### @1=1 /* INT meta=0 nullable=0 is_null=0 */
851 ### @2=´pear´ /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
852 ### @3=´2009:01:01´ /* DATE meta=0 nullable=1 is_null=0 */
853
854 You can tell mysqlbinlog to suppress the BINLOG statements for row
855 events by using the --base64-output=DECODE-ROWS option. This is similar
856 to --base64-output=NEVER but does not exit with an error if a row event
857 is found. The combination of --base64-output=DECODE-ROWS and --verbose
858 provides a convenient way to see row events only as SQL statements:
859
860 shell> mysqlbinlog -v --base64-output=DECODE-ROWS log_file
861 ...
862 # at 218
863 #080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
864 ### INSERT INTO test.t
865 ### SET
866 ### @1=1
867 ### @2=´apple´
868 ### @3=NULL
869 ...
870 # at 302
871 #080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
872 ### UPDATE test.t
873 ### WHERE
874 ### @1=1
875 ### @2=´apple´
876 ### @3=NULL
877 ### SET
878 ### @1=1
879 ### @2=´pear´
880 ### @3=´2009:01:01´
881 ...
882 # at 400
883 #080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
884 ### DELETE FROM test.t
885 ### WHERE
886 ### @1=1
887 ### @2=´pear´
888 ### @3=´2009:01:01´
889
890
891 Note
892 You should not suppress BINLOG statements if you intend to
893 re-execute mysqlbinlog output.
894
895 The SQL statements produced by --verbose for row events are much more
896 readable than the corresponding BINLOG statements. However, they do not
897 correspond exactly to the original SQL statements that generated the
898 events. The following limitations apply:
899
900 • The original column names are lost and replaced by @N, where N is a
901 column number.
902
903 • Character set information is not available in the binary log, which
904 affects string column display:
905
906 • There is no distinction made between corresponding binary and
907 nonbinary string types (BINARY and CHAR, VARBINARY and VARCHAR,
908 BLOB and TEXT). The output uses a data type of STRING for
909 fixed-length strings and VARSTRING for variable-length strings.
910
911 • For multi-byte character sets, the maximum number of bytes per
912 character is not present in the binary log, so the length for
913 string types is displayed in bytes rather than in characters.
914 For example, STRING(4) will be used as the data type for values
915 from either of these column types:
916
917 CHAR(4) CHARACTER SET latin1
918 CHAR(2) CHARACTER SET ucs2
919
920 • Due to the storage format for events of type UPDATE_ROWS_EVENT,
921 UPDATE statements are displayed with the WHERE clause preceding
922 the SET clause.
923
924 Proper interpretation of row events requires the information from the
925 format description event at the beginning of the binary log. Because
926 mysqlbinlog does not know in advance whether the rest of the log
927 contains row events, by default it displays the format description
928 event using a BINLOG statement in the initial part of the output.
929
930 If the binary log is known not to contain any events requiring a BINLOG
931 statement (that is, no row events), the --base64-output=NEVER option
932 can be used to prevent this header from being written.
933
935 Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc.,
936 2010-2021 MariaDB Foundation
937
938 This documentation is free software; you can redistribute it and/or
939 modify it only under the terms of the GNU General Public License as
940 published by the Free Software Foundation; version 2 of the License.
941
942 This documentation is distributed in the hope that it will be useful,
943 but WITHOUT ANY WARRANTY; without even the implied warranty of
944 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
945 General Public License for more details.
946
947 You should have received a copy of the GNU General Public License along
948 with the program; if not, write to the Free Software Foundation, Inc.,
949 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA or see
950 http://www.gnu.org/licenses/.
951
952
954 1. Bug#42941
955 http://bugs.mysql.com/bug.php?id=42941
956
958 For more information, please refer to the MariaDB Knowledge Base,
959 available online at https://mariadb.com/kb/
960
962 MariaDB Foundation (http://www.mariadb.org/).
963
964
965
966MariaDB 10.5 14 April 2021 MARIADB-BINLOG(1)