查看binlog文件的2种方式
1.使用show binlog events
a.获取binlog文件列表
mysql> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000005 | 1288 |
| mysql-bin.000006 | 120 |
+------------------+-----------+
mysql> b.查看当前正在写入的binlog文件
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000006
Position: 120 c.查看指定binlog文件的内容语法:
SHOW BINLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count] 1.演示查看一个二进制文件中全部事务
注:binlog文件实际上是由一连串的event组成的一个组,即事务组。
mysql> SHOW BINLOG EVENTS IN 'mysql-bin.000005' \G
*************************** 1. row *************************** 一个row代表一个事务组
Log_name: mysql-bin.000005
Pos: 4
Event_type: Format_desc
Server_id: 1
End_log_pos: 120
Info: Server ver: 5.6.29-log, Binlog ver: 4
*************************** 2. row ***************************
Log_name: mysql-bin.000005
Pos: 120
Event_type: Query
Server_id: 1
End_log_pos: 194
Info: BEGIN 2.演示对一个二进制文件的事务做过滤查询
mysql> SHOW BINLOG EVENTS IN 'mysql-bin.000005' FROM 194 LIMIT 2 \G;
*************************** 1. row ***************************
Log_name: mysql-bin.000005
Pos: 194
Event_type: Query
Server_id: 1
End_log_pos: 319
Info: use `tpcc`; UPDATE warehouse SET w_ytd = w_ytd + 3232 WHERE w_id = 1
*************************** 2. row ***************************
Log_name: mysql-bin.000005
Pos: 319
Event_type: Query
Server_id: 1
End_log_pos: 458
Info: use `tpcc`; UPDATE district SET d_ytd = d_ytd + 3232 WHERE d_w_id = 1 AND d_id = 3
2 rows in set (0.00 sec)
mysql>
2.使用mysqlbinlog查看binlog(转:http://blog.csdn.net/leshami/article/details/41962243)
a、提取指定的binlog日志
# mysqlbinlog /opt/data/APP01bin.000001
# mysqlbinlog /opt/data/APP01bin.000001|grep insert
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
insert into tb values(2,'jack') b、提取指定position位置的binlog日志
# mysqlbinlog --start-position="120" --stop-position="332" /opt/data/APP01bin.000001 c、提取指定position位置的binlog日志并输出到压缩文件
# mysqlbinlog --start-position="120" --stop-position="332" /opt/data/APP01bin.000001 |gzip >extra_01.sql.gz d、提取指定position位置的binlog日志导入数据库
# mysqlbinlog --start-position="120" --stop-position="332" /opt/data/APP01bin.000001 | mysql -uroot -p e、提取指定开始时间的binlog并输出到日志文件
# mysqlbinlog --start-datetime="2014-12-15 20:15:23" /opt/data/APP01bin.000002 --result-file=extra02.sql f、提取指定位置的多个binlog日志文件
# mysqlbinlog --start-position="120" --stop-position="332" /opt/data/APP01bin.000001 /opt/data/APP01bin.000002|more g、提取指定数据库binlog并转换字符集到UTF8
# mysqlbinlog --database=test --set-charset=utf8 /opt/data/APP01bin.000001 /opt/data/APP01bin.000002 >test.sql h、远程提取日志,指定结束时间
# mysqlbinlog -urobin -p -h192.168.1.116 -P3306 --stop-datetime="2014-12-15 20:30:23" --read-from-remote-server mysql-bin.000033 |more i、远程提取使用row格式的binlog日志并输出到本地文件
# mysqlbinlog -urobin -p -P3606 -h192.168.1.177 --read-from-remote-server -vv inst3606bin.000005 >row.sql
3.mysqlbinlog 查看row模式的binlog
当bin-log的模式设置为row时(binlog_format=row),查看执行的sql时也稍微麻烦一点,默认解析出来的结果是这样的 -bash-4.1$ /opt/mysql/bin/mysqlbinlog /opt/mysql/var/mysql-bin.000004|more
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#160614 23:18:20 server id 1 end_log_pos 120 CRC32 0xbb07feb7 Start: binlog v 4, server v 5.6.14-log created 160614 23:18:20 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
PCBgVw8BAAAAdAAAAHgAAAABAAQANS42LjE0LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAA8IGBXEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAAbf+
B7s=
'/*!*/;
完全看不懂,这时需要添加参数(--base64-output=decode-rows -v)对输出结果解码。
-bash-4.1$ /opt/mysql/bin/mysqlbinlog --base64-output=decode-rows -v /opt/mysql/var/mysql-bin.000004|more
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#160614 23:18:20 server id 1 end_log_pos 120 CRC32 0xbb07feb7 Start: binlog v 4, server v 5.6.14-log created 160614 23:18:20 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
# at 120
#160615 10:46:11 server id 1 end_log_pos 195 CRC32 0x9579c284 Query thread_id=5 exec_time=0 error_code=0
SET TIMESTAMP=1465958771/*!*/;
SET @@session.pseudo_thread_id=5/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1073741824/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 195
#160615 10:46:11 server id 1 end_log_pos 300 CRC32 0xfadf2614 Table_map: `dentist`.`ds_case_no_type` mapped to number 93
# at 300
#160615 10:46:11 server id 1 end_log_pos 690 CRC32 0x210669fe Update_rows: table id 93 flags: STMT_END_F
### UPDATE `dentist`.`ds_case_no_type`
### WHERE
### @1='736666419b3a40d9b384a03311baf2be'
### @2='5'
### @3=NULL
### @4=NULL
### @5='88'
### @6='66'
### @7='1500000000'
### @8='1500000006'
### @9=NULL
### @10='0'
### @11=NULL
### @12='c9c8d05d4d3b44379598dde5d02f1552'
### @13='2016-06-07 17:03:57'
### @14='c9c8d05d4d3b44379598dde5d02f1552'
### @15='2016-06-12 13:17:33'
### @16='67e05761a61243b68e4b259386dc0dc8'
### SET
### @1='736666419b3a40d9b384a03311baf2be'
### @2='5'
### @3=NULL
### @4=NULL
### @5='88'
### @6='66'
### @7='1500000000'
### @8='1500000007'
### @9=NULL
### @10='0'
### @11=NULL
### @12='c9c8d05d4d3b44379598dde5d02f1552'
### @13='2016-06-07 17:03:57'
### @14='c9c8d05d4d3b44379598dde5d02f1552'
### @15='2016-06-12 13:17:33'
### @16='67e05761a61243b68e4b259386dc0dc8'
# at 690
#160615 10:46:11 server id 1 end_log_pos 721 CRC32 0x70d0f695 Xid = 699
COMMIT/*!*/;
# at 721
查看binlog文件的2种方式的更多相关文章
- Eclipse项目中引用第三方jar包时将项目打包成jar文件的两种方式
转载自:http://www.cnblogs.com/lanxuezaipiao/p/3291641.html 方案一:用Eclipse自带的Export功能 步骤1:准备主清单文件 “MANIFES ...
- C#中的Excel操作【1】——设置Excel单元格的内容,打开Excel文件的一种方式
前言 作为项目管理大队中的一员,在公司里面接触最多的就是Excel文件了,所以一开始就想从Excel入手,学习简单的二次开发,开始自己的编程之路! 程序界面 功能说明 打开文件按钮,可以由使用者指定要 ...
- 前端js,css文件合并三种方式,bat命令
前端js,css文件合并三种方式,bat命令 前端js文件该如何合并三个方式如下:1. 一个大文件,所有js合并成一个大文件,所有页面都引用它.2. 各个页面大文件,各自页面合并生成自己所需js的大文 ...
- android中解析文件的三种方式
android中解析文件的三种方式 好久没有动手写点东西了,最近在研究android的相关技术,现在就android中解析文件的三种方式做以下总结.其主要有:SAX(Simple API fo ...
- java读取XML文件的四种方式
java读取XML文件的四种方式 Xml代码 <?xml version="1.0" encoding="GB2312"?> <RESULT& ...
- Android开发之合并文件的几种方式
以下介绍合并文件的几种方式,并通过合并amr文件来举例介绍合并文件的详细流程.amr格式的文件头是6字节,所以在进行文件合并的时候要减去除第一个文件以外的其它文件的文件头. 注意:不同文件的文件头是不 ...
- 加载xib文件的两种方式
一.加载xib文件的两种方式 1.方法一(NewsCell是xib文件的名称) NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@&quo ...
- js 图片base64转file文件的两种方式
js 图片base64转file文件的两种方式 https://blog.csdn.net/yin13037173186/article/details/83302628 //将base64转换为bl ...
- 转 Velocity中加载vm文件的三种方式
Velocity中加载vm文件的三种方式 velocitypropertiespath Velocity中加载vm文件的三种方式: 方式一:加载classpath目录下的vm文件 Prope ...
随机推荐
- jdk集合常用方法分析之ArrayList&LinkedList&以及两者的对比分析
集合使用注意事项: 1.集合当中只能放置对象的引用,无法放置原生数据类型,我们需要使用原生数据类型的包装类才能加入到集合当中去(JDK5之后会进行自动的装箱和拆箱操作,表面上看集合中是可以直接放置原生 ...
- Android开发-API指南-<uses-feature>
<uses-feature> 英文原文:http://developer.android.com/guide/topics/manifest/uses-feature-element.ht ...
- C#中的委托,匿名方法和Lambda表达式
简介 在.NET中,委托,匿名方法和Lambda表达式很容易发生混淆.我想下面的代码能证实这点.下面哪一个First会被编译?哪一个会返回我们需要的结果?即Customer.ID=.答案是6个Firs ...
- pb中读取大文本数据
string ls_FileName,lb_FileDatas,lb_FileData long ll_FileLen,ll_Handle,ll_Loop,ll_Bytes,ll_Loops,ll_ ...
- 避免使用CreateThread函数,导致的内存泄露
原文链接:http://blog.csdn.net/solosure/article/details/6262877
- Some regret....
今天是一个败笔,早上10点才起床,下午又不专心看书,晚上把还是不能静下来...... 把所有的时间都花在了那一篇FlowVisor上了,但是却没有任何收获,居然没看懂,等下好好整理一下逻辑. 明天开始 ...
- C# 清空sessin
Session.Abandon();//清除全部Session//清除某个SessionSession["UserName"] = null;Session.Remove(&quo ...
- 4种kill某个用户所有进程的方法
在linux系统管理中,我们有时候需要kill掉某个用户的所有进程,初学者一般先查询出用户的所有pid,然后一条条kill掉,或者写好一个脚本,实际上方法都有现成的,这边有4种方法,我们以kill用户 ...
- .net分页控件webdiyer:AspNetPager
首先下载:AspNetPager.dll AspNetPager.xml 放到bin目录下 页面添加<%@ Register Assembly="AspNetPager" ...
- projecteuler Smallest multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any rema ...