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 databasecontents. 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复制异常]'Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.'
- MySQL:Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEM
- MySQL:Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT...
- ActiveMQ中使用mysql做持久化报错:Cannot execute statement: impossible to write to binary log since BINLOG_FORM
- [MySQL复制异常]Cannot execute statement: impossible to write to binary log since statement is in row for
- [MySQL复制异常]Cannot execute statement: impossible to write to binary log since statement is in row for
- MySQL:Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEM
- JAVA调用mysql数据操作时出现错误:impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.'
- ActiveMQ中使用mysql做持久化报错:Cannot execute statement: impossible to write to binary log since BINLOG_FORM
- 【转】[MySQL复制异常]Cannot execute statement: impossible to write to binary log since statement is in row for
- Why MySQL replication is better than mysqlbinlog for recovery
- error: 'Failed to open logfile '/var/lib/mysql_ndbd/data/ndb_2_out.log' for write
- impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT
- Binary Log Group Commit in MySQL 5.6
- PHP Client for Mysql Binlog
- mysql问题之slow log中出现大量的binlog dump记录的解决方法
- the setup controller has encountered a problem during install.Please review the log files for furthe
- mysql问题之slow log中出现大量的binlog dump记录的解决方法
- MySQL中的重做日志(redo log),回滚日志(undo log),以及二进制日志(binlog)的简单总结
- 解决 "Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"