您的位置:首页 > 数据库 > MySQL

mysqlbinlog — Utility for Processing Binary Log Files

2018-03-28 15:50 459 查看

使用mysqlbinlog分析二进制日志文件

The server’s binary log consists of files containing “events” that describe modifications to database

contents. The server writes these files in binary format. To display their contents in text format, use the mysqlbinlog utility. You can also use mysqlbinlog to display the contents of relay log files written by a slave server in a replication setup because relay logs have the same format as binary logs.

Invoke mysqlbinlog like this:

shell> mysqlbinlog [options] log_file …

For example, to display the contents of the binary log file named binlog.000003, use this command:

shell> mysqlbinlog binlog.0000003

The output includes events contained in binlog.000003. For statement-based logging, event information includes the SQL statement, the ID of the server on which it was executed, the timestamp when the statement was executed, how much time it took, and so forth. For row-based logging, the event indicates a row change rather than an SQL statement.

Events are preceded by header comments that provide additional information. For example:



In the first line, the number following at indicates the file offset, or starting position, of the event in the binary log file.

The second line starts with a date and time indicating when the statement started on the server where the event originated. For replication, this timestamp is propagated to slave servers. server id is the server_id value of the server where the event originated. end_log_pos indicates where the next event starts (that is, it is the end position of the current event + 1). thread_id indicates which thread executed the event. exec_time is the time spent executing the event, on a master server. On a slave, it is the difference of the end execution time on the slave minus the beginning execution time on the master. The difference serves as an indicator of how much replication lags behind the master. error_code indicates the result from executing the event. Zero means that no error occurred.

The output from mysqlbinlog can be re-executed (for example, by using it as input to mysql) to

redo the statements in the log. This is useful for recovery operations after a server crash.

Normally, you use mysqlbinlog to read binary log files directly and apply them to the local MySQL

server. It is also possible to read binary logs from a remote server by using the –read-from-remoteserver option. To read remote binary logs, the connection parameter options can be given to indicate how to connect to the server. These options are –host, –password, –port, –protocol, –socket, and –user; they are ignored except when you also use the –read-from-remote-server option.

When running mysqlbinlog against a large binary log, be careful that the filesystem has enough space for the resulting files. To configure the directory that mysqlbinlog uses for temporary files, use the TMPDIR environment variable.

关于mysqlbinlog的介绍有很多,这里就不一一说明了。下面给出mysqlbinlog的官方链接:

mysqlbinlog官方文档
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql
相关文章推荐