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

MYSQLBINLOG HEX DUMP FORMAT

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

MYSQLBINLOG ROW EVENT DISPLAY

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

NOTES

934        1. Bug#42941
935           http://bugs.mysql.com/bug.php?id=42941
936

SEE ALSO

938       For more information, please refer to the MySQL Reference Manual, which
939       may already be installed locally and which is also available online at
940       http://dev.mysql.com/doc/.
941

AUTHOR

943       Sun Microsystems, Inc. (http://www.mysql.com/).
944
945
946
947MySQL 5.1                         04/06/2010                    MYSQLBINLOG(1)
Impressum