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       ·   --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

MYSQLBINLOG HEX DUMP FORMAT

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

MYSQLBINLOG ROW EVENT DISPLAY

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-2015 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

NOTES

954        1. Bug#42941
955           http://bugs.mysql.com/bug.php?id=42941
956

SEE ALSO

958       For more information, please refer to the MariaDB Knowledge Base,
959       available online at https://mariadb.com/kb/
960

AUTHOR

962       MariaDB Foundation (http://www.mariadb.org/).
963
964
965
966MariaDB 10.4                     28 March 2019                  MYSQLBINLOG(1)
Impressum