MYSQLBINLOG(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 binary log files that the server generates are written in binary
13       format. To examine these files in text format, use the mysqlbinlog
14       utility. You can also use mysqlbinlog to read relay log files written
15       by a slave server in a replication setup. Relay logs have the same
16       format as binary log files.
17
18       Invoke mysqlbinlog like this:
19
20          shell> mysqlbinlog [options] log_file ...
21
22       For example, to display the contents of the binary log file named
23       binlog.000003, use this command:
24
25          shell> mysqlbinlog binlog.0000003
26
27       The output includes all events contained in binlog.000003. Event
28       information includes the statement executed, the time the statement
29       took, the thread ID of the client that issued it, the timestamp when it
30       was executed, and so forth.
31
32       The output from mysqlbinlog can be re-executed (for example, by using
33       it as input to mysql) to reapply the statements in the log. This is
34       useful for recovery operations after a server crash. For other usage
35       examples, see the discussion later in this section.
36
37       Normally, you use mysqlbinlog to read binary log files directly and
38       apply them to the local MySQL server. It is also possible to read
39       binary logs from a remote server by using the --read-from-remote-server
40       option. When you read remote binary logs, the connection parameter
41       options can be given to indicate how to connect to the server. These
42       options are --host, --password, --port, --protocol, --socket, and
43       --user; they are ignored except when you also use the
44       --read-from-remote-server option.
45
46       Binary logs and relay logs are discussed further in Section 9.3, “The
47       Binary Log”, and Section 3.5, “Replication Relay and Status Files”.
48
49       mysqlbinlog supports the following options:
50
51       ·  --help, -?
52
53          Display a help message and exit.
54
55       ·  --character-sets-dir=path
56
57          The directory where character sets are installed. See Section 8.1,
58          “The Character Set Used for Data and Sorting”.
59
60       ·  --database=db_name, -d db_name
61
62          List entries for just this database (local log only). You can only
63          specify one database with this option - if you specify multiple
64          --database options, only the last one is used. This option forces
65          mysqlbinlog to output entries from the binary log where the default
66          database (that is, the one selected by USE) is db_name. Note that
67          this does not replicate cross-database statements such as UPDATE
68          some_db.some_table SET foo='bar' while having selected a different
69          database or no database.
70
71       ·  --debug[=debug_options], -# [debug_options]
72
73          Write a debugging log. A typical debug_options string is often
74          ´d:t:o,file_name'.
75
76       ·  --disable-log-bin, -D
77
78          Disable binary logging. This is useful for avoiding an endless loop
79          if you use the --to-last-log option and are sending the output to
80          the same MySQL server. This option also is useful when restoring
81          after a crash to avoid duplication of the statements you have
82          logged.
83
84          This option requires that you have the SUPER privilege. It causes
85          mysqlbinlog to include a SET SQL_LOG_BIN=0 statement in its output
86          to disable binary logging of the remaining output. The SET statement
87          is ineffective unless you have the SUPER privilege.
88
89       ·  --force-read, -f
90
91          With this option, if mysqlbinlog reads a binary log event that it
92          does not recognize, it prints a warning, ignores the event, and
93          continues. Without this option, mysqlbinlog stops if it reads such
94          an event.
95
96       ·  --hexdump, -H
97
98          Display a hex dump of the log in comments. This output can be
99          helpful for replication debugging. Hex dump format is discussed
100          later in this section. This option was added in MySQL 5.0.16.
101
102       ·  --host=host_name, -h host_name
103
104          Get the binary log from the MySQL server on the given host.
105
106       ·  --local-load=path, -l path
107
108          Prepare local temporary files for LOAD DATA INFILE in the specified
109          directory.
110
111       ·  --offset=N, -o N
112
113          Skip the first N entries in the log.
114
115       ·  --password[=password], -p[password]
116
117          The password to use when connecting to the server. If you use the
118          short option form (-p), you cannot have a space between the option
119          and the password. If you omit the password value following the
120          --password or -p option on the command line, you are prompted for
121          one.
122
123          Specifying a password on the command line should be considered
124          insecure. See Section 6.6, “Keeping Your Password Secure”.
125
126       ·  --port=port_num, -P port_num
127
128          The TCP/IP port number to use for connecting to a remote server.
129
130       ·  --position=N, -j N
131
132          Deprecated. Use --start-position instead.
133
134       ·  --protocol={TCP|SOCKET|PIPE|MEMORY}
135
136          The connection protocol to use.
137
138       ·  --read-from-remote-server, -R
139
140          Read the binary log from a MySQL server rather than reading a local
141          log file. Any connection parameter options are ignored unless this
142          option is given as well. These options are --host, --password,
143          --port, --protocol, --socket, and --user.
144
145       ·  --result-file=name, -r name
146
147          Direct output to the given file.
148
149       ·  --set-charset=charset_name
150
151          Add a SET NAMES charset_name statement to the output to specify the
152          character set to be used for processing log files. This option was
153          added in MySQL 5.0.23.
154
155       ·  --short-form, -s
156
157          Display only the statements contained in the log, without any extra
158          information.
159
160       ·  --socket=path, -S path
161
162          For connections to localhost, the Unix socket file to use, or, on
163          Windows, the name of the named pipe to use.
164
165       ·  --start-datetime=datetime
166
167          Start reading the binary log at the first event having a timestamp
168          equal to or later than the datetime argument. The datetime value is
169          relative to the local time zone on the machine where you run
170          mysqlbinlog. The value should be in a format accepted for the
171          DATETIME or TIMESTAMP data types. For example:
172
173          shell> mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000003
174       This option is useful for point-in-time recovery. See Section 7.2,
175       “Example Backup and Recovery Strategy”.
176
177       ·  --stop-datetime=datetime
178
179          Stop reading the binary log at the first event having a timestamp
180          equal or posterior to the datetime argument. This option is useful
181          for point-in-time recovery. See the description of the
182          --start-datetime option for information about the datetime value.
183
184       ·  --start-position=N
185
186          Start reading the binary log at the first event having a position
187          equal to the N argument. This option applies to the first log file
188          named on the command line.
189
190       ·  --stop-position=N
191
192          Stop reading the binary log at the first event having a position
193          equal or greater than the N argument. This option applies to the
194          last log file named on the command line.
195
196       ·  --to-last-log, -t
197
198          Do not stop at the end of the requested binary log from a MySQL
199          server, but rather continue printing until the end of the last
200          binary log. If you send the output to the same MySQL server, this
201          may lead to an endless loop. This option requires
202          --read-from-remote-server.
203
204       ·  --user=user_name, -u user_name
205
206          The MySQL username to use when connecting to a remote server.
207
208       ·  --version, -V
209
210          Display version information and exit.
211
212
213       You can also set the following variable by using --var_name=value
214       syntax:
215
216       ·  open_files_limit
217
218          Specify the number of open file descriptors to reserve.
219
220
221       It is also possible to set variables by using
222       --set-variable=var_name=value or -O var_name=value syntax.  This syntax
223       is deprecated.
224
225       You can pipe the output of mysqlbinlog into the mysql client to execute
226       the statements contained in the binary log. This is used to recover
227       from a crash when you have an old backup (see Section 7.1, “Database
228       Backups”). For example:
229
230          shell> mysqlbinlog binlog.000001 | mysql
231
232       Or:
233
234          shell> mysqlbinlog binlog.[0-9]* | mysql
235
236       You can also redirect the output of mysqlbinlog to a text file instead,
237       if you need to modify the statement log first (for example, to remove
238       statements that you do not want to execute for some reason). After
239       editing the file, execute the statements that it contains by using it
240       as input to the mysql program.
241
242       mysqlbinlog has the --start-position option, which prints only those
243       statements with an offset in the binary log greater than or equal to a
244       given position (the given position must match the start of one event).
245       It also has options to stop and start when it sees an event with a
246       given date and time. This enables you to perform point-in-time recovery
247       using the --stop-datetime option (to be able to say, for example, “roll
248       forward my databases to how they were today at 10:30 a.m.”).
249
250       If you have more than one binary log to execute on the MySQL server,
251       the safe method is to process them all using a single connection to the
252       server. Here is an example that demonstrates what may be unsafe:
253
254          shell> mysqlbinlog binlog.000001 | mysql # DANGER!!
255          shell> mysqlbinlog binlog.000002 | mysql # DANGER!!
256
257       Processing binary logs this way using different connections to the
258       server causes problems if the first log file contains a CREATE
259       TEMPORARY TABLE statement and the second log contains a statement that
260       uses the temporary table. When the first mysql process terminates, the
261       server drops the temporary table. When the second mysql process
262       attempts to use the table, the server reports “unknown table.”
263
264       To avoid problems like this, use a single connection to execute the
265       contents of all binary logs that you want to process. Here is one way
266       to do so:
267
268          shell> mysqlbinlog binlog.000001 binlog.000002 | mysql
269
270       Another approach is to write all the logs to a single file and then
271       process the file:
272
273          shell> mysqlbinlog binlog.000001 >  /tmp/statements.sql
274          shell> mysqlbinlog binlog.000002 >> /tmp/statements.sql
275          shell> mysql -e "source /tmp/statements.sql"
276
277       mysqlbinlog can produce output that reproduces a LOAD DATA INFILE
278       operation without the original data file.  mysqlbinlog copies the data
279       to a temporary file and writes a LOAD DATA LOCAL INFILE statement that
280       refers to the file. The default location of the directory where these
281       files are written is system-specific. To specify a directory
282       explicitly, use the --local-load option.
283
284       Because mysqlbinlog converts LOAD DATA INFILE statements to LOAD DATA
285       LOCAL INFILE statements (that is, it adds LOCAL), both the client and
286       the server that you use to process the statements must be configured to
287       allow LOCAL capability. See Section 4.4, “Security Issues with LOAD
288       DATA LOCAL”.
289
290       MySQL Enterprise. For expert advice on the security implications of
291       enabling LOCAL, subscribe to the MySQL Network Monitoring and Advisory
292       Service. For more information see
293       http://www.mysql.com/products/enterprise/advisors.html.
294
295       Warning: The temporary files created for LOAD DATA LOCAL statements are
296       not automatically deleted because they are needed until you actually
297       execute those statements. You should delete the temporary files
298       yourself after you no longer need the statement log. The files can be
299       found in the temporary file directory and have names like
300       original_file_name-#-#.
301
302       The --hexdump option produces a hex dump of the log contents in
303       comments:
304
305          shell> mysqlbinlog --hexdump master-bin.000001
306
307       With the preceding command, the output might look like this:
308
309          /*!40019 SET @@session.max_insert_delayed_threads=0*/;
310          /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
311          # at 4
312          #051024 17:24:13 server id 1  end_log_pos 98
313          # Position  Timestamp   Type   Master ID        Size      Master Pos    Flags
314          # 00000004 9d fc 5c 43   0f   01 00 00 00   5e 00 00 00   62 00 00 00   00 00
315          # 00000017 04 00 35 2e 30 2e 31 35  2d 64 65 62 75 67 2d 6c |..5.0.15.debug.l|
316          # 00000027 6f 67 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |og..............|
317          # 00000037 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |................|
318          # 00000047 00 00 00 00 9d fc 5c 43  13 38 0d 00 08 00 12 00 |.......C.8......|
319          # 00000057 04 04 04 04 12 00 00 4b  00 04 1a                |.......K...|
320          #       Start: binlog v 4, server v 5.0.15-debug-log created 051024 17:24:13
321          #       at startup
322          ROLLBACK;
323
324       Hex dump output currently contains the following elements. This format
325       might change in the future.
326
327       ·  Position: The byte position within the log file.
328
329       ·  Timestamp: The event timestamp. In the example shown, ´9d fc 5c 43'
330          is the representation of ´051024 17:24:13' in hexadecimal.
331
332       ·  Type: The type of the log event. In the example shown, ´0f' means
333          that the example event is a FORMAT_DESCRIPTION_EVENT. The following
334          table lists the possible types.
335
336          ┌─────┬──────────────────────────┬────────────────────────────────────────┐
337          │Type │ Name                     │ Meaning                                │
338          ├─────┼──────────────────────────┼────────────────────────────────────────┤
339          │08   │ CREATE_FILE_EVENT        │ Used for LOAD DATA                     │
340          │     │                          │ INFILE statements.                     │
341          │     │                          │ This indicates                         │
342          │     │                          │                       the              │
343          │     │                          │ start of execution                     │
344          │     │                          │ of such a                              │
345          │     │                          │ statement. A                           │
346          │     │                          │                       temporary        │
347          │     │                          │ file is created on                     │
348          │     │                          │ the slave. Used in                     │
349          │     │                          │                       MySQL            │
350          │     │                          │ 4 only.                                │
351          ├─────┼──────────────────────────┼────────────────────────────────────────┤
352          │09   │ APPEND_BLOCK_EVENT       │ Contains data for use in a LOAD        │
353          │     │                          │ DATA INFILE                            │
354          │     │                          │                       statement.       │
355          │     │                          │ The data is stored in the              │
356          │     │                          │ temporary                              │
357          │     │                          │                       file on          │
358          │     │                          │ the slave.                             │
359          ├─────┼──────────────────────────┼────────────────────────────────────────┤
360          │0a   │ EXEC_LOAD_EVENT          │ Used for LOAD DATA INFILE              │
361          │     │                          │ statements. The contents of            │
362          │     │                          │                       the              │
363          │     │                          │ temporary file is stored in the        │
364          │     │                          │ table on the                           │
365          │     │                          │                       slave.           │
366          │     │                          │ Used in MySQL 4 only.                  │
367          ├─────┼──────────────────────────┼────────────────────────────────────────┤
368          │0b   │ DELETE_FILE_EVENT        │ Rollback of a LOAD DATA INFILE         │
369          │     │                          │ statement. The                         │
370          │     │                          │                       temporary        │
371          │     │                          │ file should be deleted on slave.       │
372          ├─────┼──────────────────────────┼────────────────────────────────────────┤
373          │0c   │ NEW_LOAD_EVENT           │ Used for LOAD DATA INFILE in           │
374          │     │                          │ MySQL 4 and earlier.                   │
375          ├─────┼──────────────────────────┼────────────────────────────────────────┤
376          │0d   │ RAND_EVENT               │ Used to send information about         │
377          │     │                          │ random values if the                   │
378          │     │                          │                       RAND()           │
379          │     │                          │ function is used in the                │
380          │     │                          │                       statement.       │
381          ├─────┼──────────────────────────┼────────────────────────────────────────┤
382          │0e   │ USER_VAR_EVENT           │ Used to replicate user                 │
383          │     │                          │ variables.                             │
384          ├─────┼──────────────────────────┼────────────────────────────────────────┤
385          │0f   │ FORMAT_DESCRIPTION_EVENT │ This indicates the start of a          │
386          │     │                          │ log file written by MySQL 5 or         │
387          │     │                          │ later.                                 │
388          ├─────┼──────────────────────────┼────────────────────────────────────────┤
389          │10   │ XID_EVENT                │ Event indicating commit of an XA       │
390          │     │                          │ transaction.                           │
391          ├─────┼──────────────────────────┼────────────────────────────────────────┤
392          │11   │ BEGIN_LOAD_QUERY_EVENT   │ Used for LOAD DATA INFILE              │
393          │     │                          │ statements in MySQL 5 and              │
394          │     │                          │                       later.           │
395          ├─────┼──────────────────────────┼────────────────────────────────────────┤
396          │00   │ UNKNOWN_EVENT            │ This event should never be             │
397          │     │                          │ present in the log.                    │
398          ├─────┼──────────────────────────┼────────────────────────────────────────┤
399          │12   │ EXECUTE_LOAD_QUERY_EVENT │ Used for LOAD DATA INFILE              │
400          │     │                          │ statements in MySQL 5 and              │
401          │     │                          │                       later.           │
402          ├─────┼──────────────────────────┼────────────────────────────────────────┤
403          │13   │ TABLE_MAP_EVENT          │ Reserved for future use.               │
404          ├─────┼──────────────────────────┼────────────────────────────────────────┤
405          │14   │ WRITE_ROWS_EVENT         │ Reserved for future use.               │
406          ├─────┼──────────────────────────┼────────────────────────────────────────┤
407          │15   │ UPDATE_ROWS_EVENT        │ Reserved for future use.               │
408          ├─────┼──────────────────────────┼────────────────────────────────────────┤
409          │16   │ DELETE_ROWS_EVENT        │ Reserved for future use.               │
410          ├─────┼──────────────────────────┼────────────────────────────────────────┤
411          │01   │ START_EVENT_V3           │ This indicates the start of a          │
412          │     │                          │ log file written by MySQL 4 or         │
413          │     │                          │ earlier.                               │
414          ├─────┼──────────────────────────┼────────────────────────────────────────┤
415          │02   │ QUERY_EVENT              │ The most common type of events.        │
416          │     │                          │ These contain statements               │
417          │     │                          │ executed on the                        │
418          │     │                          │                       master.          │
419          ├─────┼──────────────────────────┼────────────────────────────────────────┤
420          │03   │ STOP_EVENT               │ Indicates that master has              │
421          │     │                          │ stopped.                               │
422          ├─────┼──────────────────────────┼────────────────────────────────────────┤
423          │04   │ ROTATE_EVENT             │ Written when the master switches       │
424          │     │                          │ to a new log file.                     │
425          ├─────┼──────────────────────────┼────────────────────────────────────────┤
426          │05   │ INTVAR_EVENT             │ Used mainly for AUTO_INCREMENT         │
427          │     │                          │ values and when the                    │
428          │     │                          │                       LAST_INSERT_ID() │
429          │     │                          │ function is                            │
430          │     │                          │                       used in          │
431          │     │                          │ the statement.                         │
432          ├─────┼──────────────────────────┼────────────────────────────────────────┤
433          │06   │ LOAD_EVENT               │ Used for LOAD DATA INFILE in MySQL     │
434          │     │                          │ 3.23.                                  │
435          ├─────┼──────────────────────────┼────────────────────────────────────────┤
436          │07   │ SLAVE_EVENT              │ Reserved for future use.               │
437          └─────┴──────────────────────────┴────────────────────────────────────────┘
438
439       ·  Master ID: The server id of the master that created the event.
440
441       ·  Size: The size in bytes of the event.
442
443       ·  Master Pos: The position of the event in the original master log
444          file.
445
446       ·  Flags: 16 flags. Currently, the following flags are used. The others
447          are reserved for the future.
448
449          ┌─────┬─────────────────────────────┬──────────────────────────────────────────────────┐
450          │Flag │ Name                        │ Meaning                                          │
451          ├─────┼─────────────────────────────┼──────────────────────────────────────────────────┤
452          │01   │ LOG_EVENT_BINLOG_IN_USE_F   │ Log file correctly                               │
453          │     │                             │ closed. (Used only                               │
454          │     │                             │ in                                               │
455          │     │                             │                       FORMAT_DESCRIPTION_EVENT.) │
456          │     │                             │ If                                               │
457          │     │                             │                       this                       │
458          │     │                             │ flag is set (if the                              │
459          │     │                             │ flags are, for                                   │
460          │     │                             │ example,                                         │
461          │     │                             │                       '01                        │
462          │     │                             │ 00') in a                                        │
463          │     │                             │                       FORMAT_DESCRIPTION_EVENT,  │
464          │     │                             │ the                                              │
465          │     │                             │                       log                        │
466          │     │                             │ file has not been                                │
467          │     │                             │ properly closed.                                 │
468          │     │                             │ Most                                             │
469          │     │                             │                       probably                   │
470          │     │                             │ this is because of                               │
471          │     │                             │ a master crash (for                              │
472          │     │                             │                       example,                   │
473          │     │                             │ due to power                                     │
474          │     │                             │ failure).                                        │
475          ├─────┼─────────────────────────────┼──────────────────────────────────────────────────┤
476          │02   │                             │ Reserved for future use.                         │
477          ├─────┼─────────────────────────────┼──────────────────────────────────────────────────┤
478          │04   │ LOG_EVENT_THREAD_SPECIFIC_F │ Set if the event is dependent on the connection  │
479          │     │                             │ it was executed in (for                          │
480          │     │                             │                       example, '04 00'), for     │
481          │     │                             │ example,                                         │
482          │     │                             │                       if the event uses          │
483          │     │                             │ temporary tables.                                │
484          ├─────┼─────────────────────────────┼──────────────────────────────────────────────────┤
485          │08   │ LOG_EVENT_SUPPRESS_USE_F    │ Set in some circumstances when the event is not  │
486          │     │                             │ dependent on the default                         │
487          │     │                             │                       database.                  │
488          └─────┴─────────────────────────────┴──────────────────────────────────────────────────┘
489          The other flags are reserved for future use.
490
492       Copyright 1997-2007 MySQL AB
493
494       This documentation is NOT distributed under a GPL license. Use of this
495       documentation is subject to the following terms: You may create a
496       printed copy of this documentation solely for your own personal use.
497       Conversion to other formats is allowed as long as the actual content is
498       not altered or edited in any way. You shall not publish or distribute
499       this documentation in any form or on any media, except if you
500       distribute the documentation in a manner similar to how MySQL
501       disseminates it (that is, electronically for download on a Web site
502       with the software) or on a CD-ROM or similar medium, provided however
503       that the documentation is disseminated together with the software on
504       the same medium. Any other use, such as any dissemination of printed
505       copies or use of this documentation, in whole or in part, in another
506       publication, requires the prior written consent from an authorized
507       representative of MySQL AB. MySQL AB reserves any and all rights to
508       this documentation not expressly granted above.
509
510       Please email <docs@mysql.com> for more information.
511

SEE ALSO

513       For more information, please refer to the MySQL Reference Manual, which
514       may already be installed locally and which is also available online at
515       http://dev.mysql.com/doc/.
516

AUTHOR

518       MySQL AB (http://www.mysql.com/).  This software comes with no
519       warranty.
520
521
522
523MySQL 5.0                         07/04/2007                    MYSQLBINLOG(1)
Impressum