码迷,mamicode.com
首页 > 其他好文 > 详细

查看binlog文件的2种方式

时间:2016-07-08 00:00:27      阅读:445      评论:0      收藏:0      [点我收藏+]

标签:

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  

 

查看binlog文件的2种方式

标签:

原文地址:http://www.cnblogs.com/polestar/p/5651870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!