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

NAME

6       mysqlbinlog - utility for processing binary log files
7

SYNOPSIS

9       mysqlbinlog [options] log_file ...
10

DESCRIPTION

12       The server´s binary log consists of files containing “events” that
13       describe modifications to database contents. The server writes these
14       files in binary format. To display their contents in text format, use
15       the mysqlbinlog utility. You can also use mysqlbinlog to display the
16       contents of relay log files written by a slave server in a replication
17       setup because relay logs have the same format as binary logs.
18
19       Invoke mysqlbinlog like this:
20
21           shell> mysqlbinlog [options] log_file ...
22
23       For example, to display the contents of the binary log file named
24       binlog.000003, use this command:
25
26           shell> mysqlbinlog binlog.0000003
27
28       The output includes events contained in binlog.000003. For
29       statement-based logging, event information includes the SQL statement,
30       the ID of the server on which it was executed, the timestamp when the
31       statement was executed, how much time it took, and so forth. For
32       row-based logging, the event indicates a row change rather than an SQL
33       statement.
34
35       Events are preceded by header comments that provide additional
36       information. For example:
37
38           # at 141
39           #100309  9:28:36 server id 123  end_log_pos 245
40             Query thread_id=3350  exec_time=11  error_code=0
41
42       In the first line, the number following at indicates the starting
43       position of the event in the binary log file.
44
45       The second line starts with a date and time indicating when the
46       statement started on the server where the event originated. For
47       replication, this timestamp is propagated to slave servers.  server id
48       is the server_id value of the server where the event originated.
49       end_log_pos indicates where the next event starts (that is, it is the
50       end position of the current event + 1).  thread_id indicates which
51       thread executed the event.  exec_time is the time spent executing the
52       event, on a master server. On a slave, it is the difference of the end
53       execution time on the slave minus the beginning execution time on the
54       master. The difference serves as an indicator of how much replication
55       lags behind the master.  error_code indicates the result from executing
56       the event. Zero means that no error occurred.
57
58       The output from mysqlbinlog can be re-executed (for example, by using
59       it as input to mysql) to redo the statements in the log. This is useful
60       for recovery operations after a server crash. For other usage examples,
61       see the discussion later in this section.
62
63       Normally, you use mysqlbinlog to read binary log files directly and
64       apply them to the local MariaDB server. It is also possible to read
65       binary logs from a remote server by using the --read-from-remote-server
66       option. To read remote binary logs, the connection parameter options
67       can be given to indicate how to connect to the server. These options
68       are --host, --password, --port, --protocol, --socket, and --user; they
69       are ignored except when you also use the --read-from-remote-server
70       option.
71
72       mysqlbinlog supports the following options, which can be specified on
73       the command line or in the [mysqlbinlog] and [client] option file
74       groups.
75
76--help, -?
77
78           Display a help message and exit.
79
80--base64-output[=value]
81
82           This option determines when events should be displayed encoded as
83           base-64 strings using BINLOG statements. The option has these
84           allowable values (not case sensitive):
85
86           •   AUTO ("automatic") or UNSPEC ("unspecified") displays BINLOG
87               statements automatically when necessary (that is, for format
88               description events and row events). This is the default if no
89               --base64-output option is given.
90
91                   Note
92                   Automatic BINLOG display is the only safe behavior if you
93                   intend to use the output of mysqlbinlog to re-execute
94                   binary log file contents. The other option values are
95                   intended only for debugging or testing purposes because
96                   they may produce output that does not include all events in
97                   executable form.
98
99           •   ALWAYS displays BINLOG statements whenever possible. This is
100               the implied value if the option is given as --base64-output
101               without a value. Both ALWAYS and not giving a value are
102               deprecated.
103
104           •   NEVER causes BINLOG statements not to be displayed.
105               mysqlbinlog exits with an error if a row event is found that
106               must be displayed using BINLOG.
107
108           •   DECODE-ROWS specifies to mysqlbinlog that you intend for row
109               events to be decoded and displayed as commented SQL statements
110               by also specifying the --verbose option. Like NEVER,
111               DECODE-ROWS suppresses display of BINLOG statements, but unlike
112               NEVER, it does not exit with an error if a row event is found.
113               The --base64-output can be given as --base64-output or
114               --skip-base64-output (with the sense of AUTO or NEVER).
115
116               For examples that show the effect of --base64-output and
117               --verbose on row event output, see the section called
118               “MYSQLBINLOG ROW EVENT DISPLAY”.
119
120--binlog-row-event-max-size=path
121
122           The directory where character sets are installed.
123
124--character-sets-dir=path
125
126           The directory where character sets are installed.
127
128--database=db_name, -d db_name
129
130           This option causes mysqlbinlog to output entries from the binary
131           log (local log only) that occur while db_name has been selected as
132           the default database by USE.
133
134           The --database option for mysqlbinlog is similar to the
135           --binlog-do-db option for mysqld, but can be used to specify only
136           one database. If --database is given multiple times, only the last
137           instance is used.
138
139           The effects of this option depend on whether the statement-based or
140           row-based logging format is in use, in the same way that the
141           effects of --binlog-do-db depend on whether statement-based or
142           row-based logging is in use.
143
144           Statement-based logging. The --database option works as follows:
145
146           •   While db_name is the default database, statements are output
147               whether they modify tables in db_name or a different database.
148
149           •   Unless db_name is selected as the default database, statements
150               are not output, even if they modify tables in db_name.
151
152           •   There is an exception for CREATE DATABASE, ALTER DATABASE, and
153               DROP DATABASE. The database being created, altered, or dropped
154               is considered to be the default database when determining
155               whether to output the statement.
156               Suppose that the binary log was created by executing these
157               statements using statement-based-logging:
158
159                   INSERT INTO test.t1 (i) VALUES(100);
160                   INSERT INTO db2.t2 (j)  VALUES(200);
161                   USE test;
162                   INSERT INTO test.t1 (i) VALUES(101);
163                   INSERT INTO t1 (i)      VALUES(102);
164                   INSERT INTO db2.t2 (j)  VALUES(201);
165                   USE db2;
166                   INSERT INTO test.t1 (i) VALUES(103);
167                   INSERT INTO db2.t2 (j)  VALUES(202);
168                   INSERT INTO t2 (j)      VALUES(203);
169
170               mysqlbinlog --database=test does not output the first two
171               INSERT statements because there is no default database. It
172               outputs the three INSERT statements following USE test, but not
173               the three INSERT statements following USE db2.
174
175               mysqlbinlog --database=db2 does not output the first two INSERT
176               statements because there is no default database. It does not
177               output the three INSERT statements following USE test, but does
178               output the three INSERT statements following USE db2.
179
180               Row-based logging.  mysqlbinlog outputs only entries that
181               change tables belonging to db_name. The default database has no
182               effect on this. Suppose that the binary log just described was
183               created using row-based logging rather than statement-based
184               logging.  mysqlbinlog --database=test outputs only those
185               entries that modify t1 in the test database, regardless of
186               whether USE was issued or what the default database is.  If a
187               server is running with binlog_format set to MIXED and you want
188               it to be possible to use mysqlbinlog with the --database
189               option, you must ensure that tables that are modified are in
190               the database selected by USE. (In particular, no cross-database
191               updates should be used.)
192
193                   Note
194                   This option did not work correctly for mysqlbinlog with
195                   row-based logging prior to MySQL 5.1.37.
196
197--debug[=debug_options], -# [debug_options]
198
199           Write a debugging log. A typical debug_options string is
200           ´d:t:o,file_name´. The default is ´d:t:o,/tmp/mysqlbinlog.trace´.
201
202--debug-check
203
204           Print some debugging information when the program exits.
205
206--debug-info
207
208           Print debugging information and memory and CPU usage statistics
209           when the program exits.
210
211--defaults-extra-file=name
212
213           Read this file after the global files are read.
214
215--defaults-file=name
216
217           Only read default options from the given file.
218
219--default-auth=name
220
221           Default authentication client-side plugin to use.
222
223--disable-log-bin, -D
224
225           Disable binary logging. This is useful for avoiding an endless loop
226           if you use the --to-last-log option and are sending the output to
227           the same MariaDB server. This option also is useful when restoring
228           after a crash to avoid duplication of the statements you have
229           logged.
230
231           This option requires that you have the SUPER privilege. It causes
232           mysqlbinlog to include a SET sql_log_bin = 0 statement in its
233           output to disable binary logging of the remaining output. The SET
234           statement is ineffective unless you have the SUPER privilege.
235
236--force-if-open
237
238           Force if binlog was not closed properly. Defaults to on; use
239           --skip-force-if-open to disable.
240
241--force-read, -f
242
243           With this option, if mysqlbinlog reads a binary log event that it
244           does not recognize, it prints a warning, ignores the event, and
245           continues. Without this option, mysqlbinlog stops if it reads such
246           an event.
247
248--hexdump, -H
249
250           Display a hex dump of the log in comments, as described in the
251           section called “MYSQLBINLOG HEX DUMP FORMAT”. The hex output can be
252           helpful for replication debugging.
253
254--host=host_name, -h host_name
255
256           Get the binary log from the MariaDB server on the given host.
257
258--local-load=path, -l path
259
260           Prepare local temporary files for LOAD DATA INFILE in the specified
261           directory.
262
263--no-defaults
264
265           Don't read default options from any option file.
266
267--offset=N, -o N
268
269           Skip the first N entries in the log.
270
271--open-files-limit=NUM
272
273           Sets the open_files_limit variable, which is used to reserve file
274           descriptors for mysqlbinlog.
275
276--password[=password], -p[password]
277
278           The password to use when connecting to the server. If you use the
279           short option form (-p), you cannot have a space between the option
280           and the password. If you omit the password value following the
281           --password or -p option on the command line, mysqlbinlog prompts
282           for one.
283
284           Specifying a password on the command line should be considered
285           insecure. You can use an option file to avoid giving the password
286           on the command line.
287
288--plugin-dir=dir_name
289
290           Directory for client-side plugins.
291
292--print-defaults
293
294           Print the program argument list from all option files and exit.
295
296--port=port_num, -P port_num
297
298           The TCP/IP port number to use for connecting to a remote server, or
299           0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT,
300           /etc/services, built-in default (3306).
301
302--protocol={TCP|SOCKET|PIPE|MEMORY}
303
304           The connection protocol to use for connecting to the server. It is
305           useful when the other connection parameters normally would cause a
306           protocol to be used other than the one you want.
307
308--raw
309
310           Requires -R. Output raw binlog data instead of SQL statements.
311           Output files named after server logs.
312
313--read-from-remote-server, -R
314
315           Read the binary log from a MariaDB server rather than reading a
316           local log file. Any connection parameter options are ignored unless
317           this option is given as well. These options are --host, --password,
318           --port, --protocol, --socket, and --user.
319
320           This option requires that the remote server be running. It works
321           only for binary log files on the remote server, not relay log
322           files.
323
324--result-file=name, -r name
325
326           Direct output to the given file. With --raw this is a prefix for
327           the file names.
328
329--rewrite-db=name, -r name
330
331           Updates to a database with a different name than the original.
332           Example: rewrite-db='from->to'. For events that are binlogged as
333           statements, rewriting the database constitutes changing a
334           statement's default database from db1 to db2. There is no statement
335           analysis or rewrite of any kind, that is, if one specifies
336           "db1.tbl" in the statement explicitly, that occurrence won't be
337           changed to "db2.tbl". Row-based events are rewritten correctly to
338           use the new database name. Filtering (e.g. with --database=name)
339           happens after the database rewrites have been performed. If you use
340           this option on the command line and ">" has a special meaning to
341           your command interpreter, quote the value (e.g. --rewrite-
342           db="oldname->newname".
343
344--server-id=id
345
346           Display only those events created by the server having the given
347           server ID.
348
349--set-charset=charset_name
350
351           Add a SET NAMES charset_name statement to the output to specify the
352           character set to be used for processing log files.
353
354--short-form, -s
355
356           Display only the statements contained in the log, no extra info and
357           no row-based events. This is for testing only, and should not be
358           used in production systems. If you want to suppress base64-output,
359           consider using --base64-output=never instead.
360
361--socket=path, -S path
362
363           For connections to localhost, the Unix socket file to use, or, on
364           Windows, the name of the named pipe to use.
365
366--start-datetime=datetime
367
368           Start reading the binary log at the first event having a timestamp
369           equal to or later than the datetime argument. The datetime value is
370           relative to the local time zone on the machine where you run
371           mysqlbinlog. The value should be in a format accepted for the
372           DATETIME or TIMESTAMP data types. For example:
373
374               shell> mysqlbinlog --start-datetime="2014-12-25 11:25:56" binlog.000003
375
376           This option is useful for point-in-time recovery.
377
378--start-position=N, -j N
379
380           Start reading the binary log at the first event having a position
381           equal to or greater than N. This option applies to the first log
382           file named on the command line.
383
384           This option is useful for point-in-time recovery.
385
386--stop-datetime=datetime
387
388           Stop reading the binary log at the first event having a timestamp
389           equal to or later than the datetime argument. This option is useful
390           for point-in-time recovery. See the description of the
391           --start-datetime option for information about the datetime value.
392
393           This option is useful for point-in-time recovery.
394
395--stop-never
396
397           Wait for more data from the server instead of stopping at the end
398           of the last log. Implies --to-last-log.
399
400--stop-never-slave-server-id
401
402           The slave server_id used for --read-from-remote-server --stop-
403           never.
404
405--stop-position=N
406
407           Stop reading the binary log at the first event having a position
408           equal to or greater than N. This option applies to the last log
409           file named on the command line.
410
411           This option is useful for point-in-time recovery.
412
413--table, -T
414
415           List entries for just this table (local log only).
416
417--to-last-log, -t
418
419           Do not stop at the end of the requested binary log from a MariaDB
420           server, but rather continue printing until the end of the last
421           binary log. If you send the output to the same MariaDB server, this
422           may lead to an endless loop, so this option requires
423           --read-from-remote-server.
424
425--user=user_name, -u user_name
426
427           The MariaDB username to use when connecting to a remote server.
428
429--verbose, -v
430
431           Reconstruct row events and display them as commented SQL
432           statements. If this option is given twice, the output includes
433           comments to indicate column data types and some metadata.
434
435           For examples that show the effect of --base64-output and --verbose
436           on row event output, see the section called “MYSQLBINLOG ROW EVENT
437           DISPLAY”.
438
439--version, -V
440
441           Display version information and exit.
442
443       You can also set the following variable by using --var_name=value
444       syntax:
445
446       •   open_files_limit
447
448           Specify the number of open file descriptors to reserve.
449
450       You can pipe the output of mysqlbinlog into the mysql client to execute
451       the events contained in the binary log. This technique is used to
452       recover from a crash when you have an old backup. For example:
453
454           shell> mysqlbinlog binlog.000001 | mysql -u root -p
455
456       Or:
457
458           shell> mysqlbinlog binlog.[0-9]* | mysql -u root -p
459
460       You can also redirect the output of mysqlbinlog to a text file instead,
461       if you need to modify the statement log first (for example, to remove
462       statements that you do not want to execute for some reason). After
463       editing the file, execute the statements that it contains by using it
464       as input to the mysql program:
465
466           shell> mysqlbinlog binlog.000001 > tmpfile
467           shell> ... edit tmpfile ...
468           shell> mysql -u root -p < tmpfile
469
470       When mysqlbinlog is invoked with the --start-position option, it
471       displays only those events with an offset in the binary log greater
472       than or equal to a given position (the given position must match the
473       start of one event). It also has options to stop and start when it sees
474       an event with a given date and time. This enables you to perform
475       point-in-time recovery using the --stop-datetime option (to be able to
476       say, for example, “roll forward my databases to how they were today at
477       10:30 a.m.”).
478
479       If you have more than one binary log to execute on the MariaDB server,
480       the safe method is to process them all using a single connection to the
481       server. Here is an example that demonstrates what may be unsafe:
482
483           shell> mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
484           shell> mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!
485
486       Processing binary logs this way using different connections to the
487       server causes problems if the first log file contains a CREATE
488       TEMPORARY TABLE statement and the second log contains a statement that
489       uses the temporary table. When the first mysql process terminates, the
490       server drops the temporary table. When the second mysql process
491       attempts to use the table, the server reports “unknown table.”
492
493       To avoid problems like this, use a single mysql process to execute the
494       contents of all binary logs that you want to process. Here is one way
495       to do so:
496
497           shell> mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
498
499       Another approach is to write all the logs to a single file and then
500       process the file:
501
502           shell> mysqlbinlog binlog.000001 >  /tmp/statements.sql
503           shell> mysqlbinlog binlog.000002 >> /tmp/statements.sql
504           shell> mysql -u root -p -e "source /tmp/statements.sql"
505
506       mysqlbinlog can produce output that reproduces a LOAD DATA INFILE
507       operation without the original data file.  mysqlbinlog copies the data
508       to a temporary file and writes a LOAD DATA LOCAL INFILE statement that
509       refers to the file. The default location of the directory where these
510       files are written is system-specific. To specify a directory
511       explicitly, use the --local-load option.
512
513       Because mysqlbinlog converts LOAD DATA INFILE statements to LOAD DATA
514       LOCAL INFILE statements (that is, it adds LOCAL), both the client and
515       the server that you use to process the statements must be configured
516       with the LOCAL capability enabled.
517
518           Warning
519           The temporary files created for LOAD DATA LOCAL statements are not
520           automatically deleted because they are needed until you actually
521           execute those statements. You should delete the temporary files
522           yourself after you no longer need the statement log. The files can
523           be found in the temporary file directory and have names like
524           original_file_name-#-#.
525

MYSQLBINLOG HEX DUMP FORMAT

527       The --hexdump option causes mysqlbinlog to produce a hex dump of the
528       binary log contents:
529
530           shell> mysqlbinlog --hexdump master-bin.000001
531
532       The hex output consists of comment lines beginning with #, so the
533       output might look like this for the preceding command:
534
535           /*!40019 SET @@session.max_insert_delayed_threads=0*/;
536           /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
537           # at 4
538           #051024 17:24:13 server id 1  end_log_pos 98
539           # Position  Timestamp   Type   Master ID        Size      Master Pos    Flags
540           # 00000004 9d fc 5c 43   0f   01 00 00 00   5e 00 00 00   62 00 00 00   00 00
541           # 00000017 04 00 35 2e 30 2e 31 35  2d 64 65 62 75 67 2d 6c |..5.0.15.debug.l|
542           # 00000027 6f 67 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |og..............|
543           # 00000037 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |................|
544           # 00000047 00 00 00 00 9d fc 5c 43  13 38 0d 00 08 00 12 00 |.......C.8......|
545           # 00000057 04 04 04 04 12 00 00 4b  00 04 1a                |.......K...|
546           #       Start: binlog v 4, server v 5.0.15-debug-log created 051024 17:24:13
547           #       at startup
548           ROLLBACK;
549
550       Hex dump output currently contains the elements in the following list.
551       This format is subject to change. (For more information about binary
552       log format, see
553       http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log.)
554
555       •   Position: The byte position within the log file.
556
557       •   Timestamp: The event timestamp. In the example shown, ´9d fc 5c 43´
558           is the representation of ´051024 17:24:13´ in hexadecimal.
559
560       •   Type: The event type code. In the example shown, ´0f´ indicates a
561           FORMAT_DESCRIPTION_EVENT. The following table lists the possible
562           type codes.
563
564           ┌─────┬──────────────────────────┬─────────────────────────────────┐
565           │Type │ Name                     │ Meaning                         │
566           ├─────┼──────────────────────────┼─────────────────────────────────┤
567           │00   │ UNKNOWN_EVENT            │ This event should never be      │
568           │     │                          │ present in the log.             │
569           ├─────┼──────────────────────────┼─────────────────────────────────┤
570           │01   │ START_EVENT_V3           │ This indicates the start of a   │
571           │     │                          │ log file written by MySQL 4 or  │
572           │     │                          │ earlier.                        │
573           ├─────┼──────────────────────────┼─────────────────────────────────┤
574           │02   │ QUERY_EVENT              │ The most common type of events. │
575           │     │                          │ These contain statements        │
576           │     │                          │ executed on the master.         │
577           ├─────┼──────────────────────────┼─────────────────────────────────┤
578           │03   │ STOP_EVENT               │ Indicates that master has       │
579           │     │                          │ stopped.                        │
580           ├─────┼──────────────────────────┼─────────────────────────────────┤
581           │04   │ ROTATE_EVENT             │ Written when the master         │
582           │     │                          │ switches to a new log file.     │
583           ├─────┼──────────────────────────┼─────────────────────────────────┤
584           │05   │ INTVAR_EVENT             │ Used for AUTO_INCREMENT values  │
585           │     │                          │ or when the LAST_INSERT_ID()    │
586           │     │                          │ function is used in the         │
587           │     │                          │ statement.                      │
588           ├─────┼──────────────────────────┼─────────────────────────────────┤
589           │06   │ LOAD_EVENT               │ Used for LOAD DATA INFILE in    │
590           │     │                          │ MySQL 3.23.                     │
591           ├─────┼──────────────────────────┼─────────────────────────────────┤
592           │07   │ SLAVE_EVENT              │ Reserved for future use.        │
593           ├─────┼──────────────────────────┼─────────────────────────────────┤
594           │08   │ CREATE_FILE_EVENT        │ Used for LOAD DATA INFILE       │
595           │     │                          │ statements. This indicates the  │
596           │     │                          │ start of execution of such a    │
597           │     │                          │ statement. A temporary file is  │
598           │     │                          │ created on the slave. Used in   │
599           │     │                          │ MySQL 4 only.                   │
600           ├─────┼──────────────────────────┼─────────────────────────────────┤
601           │09   │ APPEND_BLOCK_EVENT       │ Contains data for use in a LOAD │
602           │     │                          │ DATA INFILE statement. The data │
603           │     │                          │ is stored in the temporary file │
604           │     │                          │ on the slave.                   │
605           ├─────┼──────────────────────────┼─────────────────────────────────┤
606           │0a   │ EXEC_LOAD_EVENT          │ Used for LOAD DATA INFILE       │
607           │     │                          │ statements. The contents of the │
608           │     │                          │ temporary file is stored in the │
609           │     │                          │ table on the slave.  Used in    │
610           │     │                          │ MySQL 4 only.                   │
611           ├─────┼──────────────────────────┼─────────────────────────────────┤
612           │0b   │ DELETE_FILE_EVENT        │ Rollback of a LOAD DATA INFILE  │
613           │     │                          │ statement. The temporary file   │
614           │     │                          │ should be deleted on the slave. │
615           ├─────┼──────────────────────────┼─────────────────────────────────┤
616           │0c   │ NEW_LOAD_EVENT           │ Used for LOAD DATA INFILE in    │
617           │     │                          │ MySQL 4 and earlier.            │
618           ├─────┼──────────────────────────┼─────────────────────────────────┤
619           │0d   │ RAND_EVENT               │ Used to send information about  │
620           │     │                          │ random values if the RAND()     │
621           │     │                          │ function is used in the         │
622           │     │                          │ statement.                      │
623           ├─────┼──────────────────────────┼─────────────────────────────────┤
624           │0e   │ USER_VAR_EVENT           │ Used to replicate user          │
625           │     │                          │ variables.                      │
626           ├─────┼──────────────────────────┼─────────────────────────────────┤
627           │0f   │ FORMAT_DESCRIPTION_EVENT │ This indicates the start of a   │
628           │     │                          │ log file written by MySQL 5 or  │
629           │     │                          │ later.                          │
630           ├─────┼──────────────────────────┼─────────────────────────────────┤
631           │10   │ XID_EVENT                │ Event indicating commit of an   │
632           │     │                          │ XA transaction.                 │
633           ├─────┼──────────────────────────┼─────────────────────────────────┤
634           │11   │ BEGIN_LOAD_QUERY_EVENT   │ Used for LOAD DATA INFILE       │
635           │     │                          │ statements in MySQL 5 and       │
636           │     │                          │ later.                          │
637           ├─────┼──────────────────────────┼─────────────────────────────────┤
638           │12   │ EXECUTE_LOAD_QUERY_EVENT │ Used for LOAD DATA INFILE       │
639           │     │                          │ statements in MySQL 5 and       │
640           │     │                          │ later.                          │
641           ├─────┼──────────────────────────┼─────────────────────────────────┤
642           │13   │ TABLE_MAP_EVENT          │ Information about a table       │
643           │     │                          │ definition. Used in MySQL 5.1.5 │
644           │     │                          │ and later.                      │
645           ├─────┼──────────────────────────┼─────────────────────────────────┤
646           │14   │ PRE_GA_WRITE_ROWS_EVENT  │ Row data for a single table     │
647           │     │                          │ that should be created. Used in │
648           │     │                          │ MySQL 5.1.5 to 5.1.17.          │
649           ├─────┼──────────────────────────┼─────────────────────────────────┤
650           │15   │ PRE_GA_UPDATE_ROWS_EVENT │ Row data for a single table     │
651           │     │                          │ that needs to be updated. Used  │
652           │     │                          │ in MySQL 5.1.5 to 5.1.17.       │
653           ├─────┼──────────────────────────┼─────────────────────────────────┤
654           │16   │ PRE_GA_DELETE_ROWS_EVENT │ Row data for a single table     │
655           │     │                          │ that should be deleted. Used in │
656           │     │                          │ MySQL 5.1.5 to 5.1.17.          │
657           ├─────┼──────────────────────────┼─────────────────────────────────┤
658           │17   │ WRITE_ROWS_EVENT         │ Row data for a single table     │
659           │     │                          │ that should be created. Used in │
660           │     │                          │ MySQL 5.1.18 and later.         │
661           ├─────┼──────────────────────────┼─────────────────────────────────┤
662           │18   │ UPDATE_ROWS_EVENT        │ Row data for a single table     │
663           │     │                          │ that needs to be updated. Used  │
664           │     │                          │ in MySQL 5.1.18 and later.      │
665           ├─────┼──────────────────────────┼─────────────────────────────────┤
666           │19   │ DELETE_ROWS_EVENT        │ Row data for a single table     │
667           │     │                          │ that should be deleted. Used in │
668           │     │                          │ MySQL 5.1.18 and later.         │
669           ├─────┼──────────────────────────┼─────────────────────────────────┤
670           │1a   │ INCIDENT_EVENT           │ Something out of the ordinary   │
671           │     │                          │ happened. Added in MySQL        │
672           │     │                          │ 5.1.18.                         │
673           └─────┴──────────────────────────┴─────────────────────────────────┘
674
675       •   Master ID: The server ID of the master that created the event.
676
677       •   Size: The size in bytes of the event.
678
679       •   Master Pos: The position of the next event in the original master
680           log file.
681
682       •   Flags: 16 flags. Currently, the following flags are used. The
683           others are reserved for future use.
684
685           ┌─────┬─────────────────────────────┬──────────────────────────────┐
686           │Flag │ Name                        │ Meaning                      │
687           ├─────┼─────────────────────────────┼──────────────────────────────┤
688           │01   │ LOG_EVENT_BINLOG_IN_USE_F   │ Log file correctly closed.   │
689           │     │                             │ (Used only in                │
690           │     │                             │ FORMAT_DESCRIPTION_EVENT.)   │
691           │     │                             │ If this flag is set (if the  │
692           │     │                             │ flags are, for example, ´01  │
693           │     │                             │ 00´) in a                    │
694           │     │                             │ FORMAT_DESCRIPTION_EVENT,    │
695           │     │                             │ the log file has not been    │
696           │     │                             │ properly closed. Most        │
697           │     │                             │ probably this is because of  │
698           │     │                             │ a master crash (for example, │
699           │     │                             │ due to power failure).       │
700           ├─────┼─────────────────────────────┼──────────────────────────────┤
701           │02   │                             │ Reserved for future use.     │
702           ├─────┼─────────────────────────────┼──────────────────────────────┤
703           │04   │ LOG_EVENT_THREAD_SPECIFIC_F │ Set if the event is          │
704           │     │                             │ dependent on the connection  │
705           │     │                             │ it was executed in (for      │
706           │     │                             │ example, ´04 00´), for       │
707           │     │                             │ example, if the event uses   │
708           │     │                             │ temporary tables.            │
709           ├─────┼─────────────────────────────┼──────────────────────────────┤
710           │08   │ LOG_EVENT_SUPPRESS_USE_F    │ Set in some circumstances    │
711           │     │                             │ when the event is not        │
712           │     │                             │ dependent on the default     │
713           │     │                             │ database.                    │
714           └─────┴─────────────────────────────┴──────────────────────────────┘
715

MYSQLBINLOG ROW EVENT DISPLAY

717       The following examples illustrate how mysqlbinlog displays row events
718       that specify data modifications. These correspond to events with the
719       WRITE_ROWS_EVENT, UPDATE_ROWS_EVENT, and DELETE_ROWS_EVENT type codes.
720       The --base64-output=DECODE-ROWS and --verbose options may be used to
721       affect row event output.
722
723       Suppose that the server is using row-based binary logging and that you
724       execute the following sequence of statements:
725
726           CREATE TABLE t
727           (
728             id   INT NOT NULL,
729             name VARCHAR(20) NOT NULL,
730             date DATE NULL
731           ) ENGINE = InnoDB;
732           START TRANSACTION;
733           INSERT INTO t VALUES(1, ´apple´, NULL);
734           UPDATE t SET name = ´pear´, date = ´2009-01-01´ WHERE id = 1;
735           DELETE FROM t WHERE id = 1;
736           COMMIT;
737
738       By default, mysqlbinlog displays row events encoded as base-64 strings
739       using BINLOG statements. Omitting extraneous lines, the output for the
740       row events produced by the preceding statement sequence looks like
741       this:
742
743           shell> mysqlbinlog log_file
744           ...
745           # at 218
746           #080828 15:03:08 server id 1  end_log_pos 258     Write_rows: table id 17 flags: STMT_END_F
747           BINLOG ´
748           fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
749           fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
750           ´/*!*/;
751           ...
752           # at 302
753           #080828 15:03:08 server id 1  end_log_pos 356     Update_rows: table id 17 flags: STMT_END_F
754           BINLOG ´
755           fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
756           fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
757           ´/*!*/;
758           ...
759           # at 400
760           #080828 15:03:08 server id 1  end_log_pos 442     Delete_rows: table id 17 flags: STMT_END_F
761           BINLOG ´
762           fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
763           fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
764           ´/*!*/;
765
766       To see the row events as comments in the form of “pseudo-SQL”
767       statements, run mysqlbinlog with the --verbose or -v option. The output
768       will contain lines beginning with ###:
769
770           shell> mysqlbinlog -v log_file
771           ...
772           # at 218
773           #080828 15:03:08 server id 1  end_log_pos 258     Write_rows: table id 17 flags: STMT_END_F
774           BINLOG ´
775           fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
776           fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
777           ´/*!*/;
778           ### INSERT INTO test.t
779           ### SET
780           ###   @1=1
781           ###   @2=´apple´
782           ###   @3=NULL
783           ...
784           # at 302
785           #080828 15:03:08 server id 1  end_log_pos 356     Update_rows: table id 17 flags: STMT_END_F
786           BINLOG ´
787           fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
788           fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
789           ´/*!*/;
790           ### UPDATE test.t
791           ### WHERE
792           ###   @1=1
793           ###   @2=´apple´
794           ###   @3=NULL
795           ### SET
796           ###   @1=1
797           ###   @2=´pear´
798           ###   @3=´2009:01:01´
799           ...
800           # at 400
801           #080828 15:03:08 server id 1  end_log_pos 442     Delete_rows: table id 17 flags: STMT_END_F
802           BINLOG ´
803           fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
804           fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
805           ´/*!*/;
806           ### DELETE FROM test.t
807           ### WHERE
808           ###   @1=1
809           ###   @2=´pear´
810           ###   @3=´2009:01:01´
811
812       Specify --verbose or -v twice to also display data types and some
813       metadata for each column. The output will contain an additional comment
814       following each column change:
815
816           shell> mysqlbinlog -vv log_file
817           ...
818           # at 218
819           #080828 15:03:08 server id 1  end_log_pos 258     Write_rows: table id 17 flags: STMT_END_F
820           BINLOG ´
821           fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
822           fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
823           ´/*!*/;
824           ### INSERT INTO test.t
825           ### SET
826           ###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
827           ###   @2=´apple´ /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
828           ###   @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
829           ...
830           # at 302
831           #080828 15:03:08 server id 1  end_log_pos 356     Update_rows: table id 17 flags: STMT_END_F
832           BINLOG ´
833           fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
834           fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
835           ´/*!*/;
836           ### UPDATE test.t
837           ### WHERE
838           ###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
839           ###   @2=´apple´ /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
840           ###   @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
841           ### SET
842           ###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
843           ###   @2=´pear´ /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
844           ###   @3=´2009:01:01´ /* DATE meta=0 nullable=1 is_null=0 */
845           ...
846           # at 400
847           #080828 15:03:08 server id 1  end_log_pos 442     Delete_rows: table id 17 flags: STMT_END_F
848           BINLOG ´
849           fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
850           fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
851           ´/*!*/;
852           ### DELETE FROM test.t
853           ### WHERE
854           ###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
855           ###   @2=´pear´ /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
856           ###   @3=´2009:01:01´ /* DATE meta=0 nullable=1 is_null=0 */
857
858       You can tell mysqlbinlog to suppress the BINLOG statements for row
859       events by using the --base64-output=DECODE-ROWS option. This is similar
860       to --base64-output=NEVER but does not exit with an error if a row event
861       is found. The combination of --base64-output=DECODE-ROWS and --verbose
862       provides a convenient way to see row events only as SQL statements:
863
864           shell> mysqlbinlog -v --base64-output=DECODE-ROWS log_file
865           ...
866           # at 218
867           #080828 15:03:08 server id 1  end_log_pos 258     Write_rows: table id 17 flags: STMT_END_F
868           ### INSERT INTO test.t
869           ### SET
870           ###   @1=1
871           ###   @2=´apple´
872           ###   @3=NULL
873           ...
874           # at 302
875           #080828 15:03:08 server id 1  end_log_pos 356     Update_rows: table id 17 flags: STMT_END_F
876           ### UPDATE test.t
877           ### WHERE
878           ###   @1=1
879           ###   @2=´apple´
880           ###   @3=NULL
881           ### SET
882           ###   @1=1
883           ###   @2=´pear´
884           ###   @3=´2009:01:01´
885           ...
886           # at 400
887           #080828 15:03:08 server id 1  end_log_pos 442     Delete_rows: table id 17 flags: STMT_END_F
888           ### DELETE FROM test.t
889           ### WHERE
890           ###   @1=1
891           ###   @2=´pear´
892           ###   @3=´2009:01:01´
893
894
895           Note
896           You should not suppress BINLOG statements if you intend to
897           re-execute mysqlbinlog output.
898
899       The SQL statements produced by --verbose for row events are much more
900       readable than the corresponding BINLOG statements. However, they do not
901       correspond exactly to the original SQL statements that generated the
902       events. The following limitations apply:
903
904       •   The original column names are lost and replaced by @N, where N is a
905           column number.
906
907       •   Character set information is not available in the binary log, which
908           affects string column display:
909
910           •   There is no distinction made between corresponding binary and
911               nonbinary string types (BINARY and CHAR, VARBINARY and VARCHAR,
912               BLOB and TEXT). The output uses a data type of STRING for
913               fixed-length strings and VARSTRING for variable-length strings.
914
915           •   For multi-byte character sets, the maximum number of bytes per
916               character is not present in the binary log, so the length for
917               string types is displayed in bytes rather than in characters.
918               For example, STRING(4) will be used as the data type for values
919               from either of these column types:
920
921                   CHAR(4) CHARACTER SET latin1
922                   CHAR(2) CHARACTER SET ucs2
923
924           •   Due to the storage format for events of type UPDATE_ROWS_EVENT,
925               UPDATE statements are displayed with the WHERE clause preceding
926               the SET clause.
927
928       Proper interpretation of row events requires the information from the
929       format description event at the beginning of the binary log. Because
930       mysqlbinlog does not know in advance whether the rest of the log
931       contains row events, by default it displays the format description
932       event using a BINLOG statement in the initial part of the output.
933
934       If the binary log is known not to contain any events requiring a BINLOG
935       statement (that is, no row events), the --base64-output=NEVER option
936       can be used to prevent this header from being written.
937
939       Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc.,
940       2010-2021 MariaDB Foundation
941
942       This documentation is free software; you can redistribute it and/or
943       modify it only under the terms of the GNU General Public License as
944       published by the Free Software Foundation; version 2 of the License.
945
946       This documentation is distributed in the hope that it will be useful,
947       but WITHOUT ANY WARRANTY; without even the implied warranty of
948       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
949       General Public License for more details.
950
951       You should have received a copy of the GNU General Public License along
952       with the program; if not, write to the Free Software Foundation, Inc.,
953       51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA or see
954       http://www.gnu.org/licenses/.
955
956

NOTES

958        1. Bug#42941
959           http://bugs.mysql.com/bug.php?id=42941
960

SEE ALSO

962       For more information, please refer to the MariaDB Knowledge Base,
963       available online at https://mariadb.com/kb/
964

AUTHOR

966       MariaDB Foundation (http://www.mariadb.org/).
967
968
969
970MariaDB 10.5                     14 April 2021                  MYSQLBINLOG(1)
Impressum