How to Read MySQL Binary Log Files (BinLog) with mysqlbinlog如何阅读MySQL的二进制日志文件( binlog )与mysqlbinlog
MySQL database server generates binary log files for every transaction to the databases, provided administrator does not disable or comment out the “log-bin” parameter in my.cny configuration file. MySQL数据库服务器生成的二进制日志文件为每交易数据库,提供了管理员没有禁用或评论,指出“在本机登录斌”参数在my.cny配置文件。 The binary log files are written in binary format.二进制日志文件都写的二进制格式。 Although the binary logs, or also known as logbin are mainly used for MySQL database replication purpose, sometimes you may need to examine or read the contents of binary logs in text format, where the mysqlbinlog utility will come in handy.虽然二进制日志,或者也称为logbin主要用于MySQL数据库复制的目的,但有时,你可能需要检查或阅读的内容二进制日志以文本格式,如mysqlbinlog实用工具能派上用场。
Binary log file, which normally has name with the format host_name-bin.xxxxxx and store in /var/lib/mysql directory, could not be opened and read straight away as it’s in unreadable binary format.二进制日志文件,该文件通常名称与格式host_name - bin.xxxxxx和商店,到/ var / lib / MySQL的目录,无法打开,并宣读了直线距离,因为它的在不可读的二进制格式。 To read the binary logs in text format, we can make use of mysqlbinlog command, which also able to readrelay log files written by a slave server in a replication setup.阅读二进制日志以文本格式,我们可以利用mysqlbinlog命令,该命令也能readrelay日志文件的书面由一个奴隶的服务器在复制设置。 Relay logs have the same format as binary log files.中继日志中有相同的格式,作为二进制日志文件。
To use mysqlbinlog utility is simple, simply use the following command syntax to invoke mysqlbinlog after login in as root (else you have to specify user name and password) to shell via SSH:使用mysqlbinlog实用工具很简单,只需使用下列命令语法引用mysqlbinlog登录后,在作为根(否则,你必须指定的用户名和密码)壳牌通过SSH :
mysqlbinlog [options] log_file … mysqlbinlog [选项] log_file …
So to read and display the contents of the binary log file named binlog.000001, use this command:因此,读取和显示的内容,该二进制日志文件,名为binlog.000001 ,使用这个命令:
mysqlbinlog binlog.000001 mysqlbinlog binlog.000001
The binary log files and its data are likely to be very huge, thus making it almost impossible to read anything on screen.二进制日志文件和数据,可能会非常庞大,从而使这几乎是不可能的阅读任何在屏幕上。 However, you can pipe the output of mysqlbinlog into a file which can be open up for later browsing in text editor, by using the following command:不过,您可以管的输出mysqlbinlog到档案中可开放供以后浏览,在文本编辑器,通过使用以下命令:
mysqlbinlog binlog.000001 > filename.txt mysqlbinlog binlog.000001 > filename.txt
To reduce the amount of data retrieved from binary logs, there are several options that can be used to limit the data that is been returned.减少的数据量来自二进制日志,有几个选项可以用来限制数据是被退回。 Among the useful ones are listed below:其中有用的列举如下:
–start-datetime=datetime -启动日期时间=日期时间
Start reading the binary log at the first event having a timestamp equal to or later than the datetime argument.开始阅读该二进制日志在第一次事件有一个时间戳记相等于或不迟于该日期时间的说法。 The datetime value is relative to the local time zone on the machine where you run mysqlbinlog.该日期时间价值是相对的,以当地时区的计算机上运行的地方,你mysqlbinlog 。 The value should be in a format accepted for the DATETIME or TIMESTAMP data types.该值应在格式接纳为日期时间或时间戳的数据类型。 For example:例如:
mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000001 mysqlbinlog -启动日期时间= “ 2 005年1 2月2 5日1 1时2 5分5 6秒” b inlog.000001
–stop-datetime=datetime 一站式日期时间=日期时间
Stop reading the binary log at the first event having a timestamp equal or posterior to the datetime argument.停止读二进制日志在第一次事件有一个时间戳等于或后向日期时间的说法。 This option is useful for point-in-time recovery.这个选项是有益的时间点复苏。 See the description of the –start-datetime option for information about the datetime value.见描述-开始日期时间的选择有关日期时间的价值。
–start-position=N 启动位置为N
Start reading the binary log at the first event having a position equal to the N argument.开始阅读该二进制日志在第一次事件有一个平等的地位,以氮的论据。 This option applies to the first log file named on the command line.这个选项适用于第一个日志文件命名的命令行。
–stop-position=N 一站式服务的立场,为N
Stop reading the binary log at the first event having a position equal or greater than the N argument.停止读二进制日志在第一次事件有一个平等的地位或大于氮的论据。 This option applies to the last log file named on the command line.这个选项适用于过去的日志文件命名的命令行。
For more usage information on mysqlbinlog, visit有关更多用法信息对mysqlbinlog ,请访问 here这里 . 。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要说明 :这是一个机器翻译网页是“按原样”提供的担保。 Machine translation may be difficult to understand.机器翻译可能很难理解。 Please refer to请参阅 original English article英文原版的文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at分享和贡献,或取得技术的支持和帮助,在 My Digital Life Forums 我的数字生活论坛 . 。
Related Articles相关文章
- Change or Set MySQL Long Query Time Value for log-slow-queries改变或设置MySQL的长期查询时间价值为登录慢的疑问
- Enable Logging of Slow Queries (Slow Query Log) in MySQL Database启用日志记录慢查询(慢速查询日志)在MySQL数据库
- How to Backup and Restore (Export and Import) MySQL Databases Tutorial如何备份和恢复(出口和进口)的MySQL数据库补习
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 1安装Web服务器在Windows XP的Apache2 , php5和mysql4 -第1部分
- Reset the Root Password of MySQL Server重置root密码的MySQL服务器
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL数据库性能调整的最佳做法视频教程
- Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 - Part 3安装Web服务器在FreeBSD的6.0与2.2的Apache , MySQL 5.0的和PHP 5 -第3部分
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 4安装Web服务器在Windows XP的Apache2 , php5和mysql4 -第4部分
- Change and Reset MySQL root Password改变和重置MySQL的root密码
- How to Find and Replace Text in MySQL Database using SQL如何查找和替换文本在MySQL数据库中使用SQL
















June 29th, 2008 16:33 2008年6月29日16时33分
This post saved my life today… when the binary log were the only way to retrieve important data get lost… thanks!!这个职位救了我的生活…今天,当二进制日志人的唯一途径检索的重要数据丢失…感谢!