手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

统计MySQL binlog中的DML语句

[日期:2014-02-05] 来源:Linux社区  作者:staricqxyz [字体:大 中 小]

统计MySQL binlog中的DML语句

MASTER@root@test 07:44:52>create table tab02(id int(10) primary key,name varchar(20)); 
Query OK, 0 rows affected (0.10 sec) 
 
MASTER@root@test 08:34:54> 
MASTER@root@test 08:34:54> 
MASTER@root@test 08:34:54>insert into tab02 values(1,'ddd'); 
Query OK, 1 row affected (0.00 sec) 
 
MASTER@root@test 08:34:59>insert into tab02 values(2,'ddd'); 
Query OK, 1 row affected (0.00 sec) 
 
MASTER@root@test 08:35:01>insert into tab02 values(3,'ddd'); 
Query OK, 1 row affected (0.00 sec) 
 
MASTER@root@test 08:35:03>insert into tab02 values(4,'ddd'); 
Query OK, 1 row affected (0.00 sec) 
 
MASTER@root@test 08:35:04>insert into tab02 values(5,'ddd'); 
Query OK, 1 row affected (0.01 sec) 
 
MASTER@root@test 08:35:07>insert into tab02 values(6,'ddd'); 
Query OK, 1 row affected (0.00 sec) 
 
MASTER@root@test 08:35:09>delete from tab02 where id=6; 
Query OK, 1 row affected (0.02 sec) 
 
MASTER@root@test 08:35:19>update tab02 set name='CD' where id=1 
    -> ; 
Query OK, 1 row affected (0.00 sec) 
Rows matched: 1  Changed: 1  Warnings: 0 
 
MASTER@root@test 08:35:39>update tab02 set name='CD' where id=3; 
Query OK, 1 row affected (0.00 sec) 
Rows matched: 1  Changed: 1  Warnings: 0 

 

[root@mynode1 mysql]# /service/mysql/bin/mysqlbinlog binlog-master.000006 |\ 
> grep -i -e "^update" -e "^insert" -e "^delete" -e "^replace" -e "^alter"  | \ 
> cut -c1-100 | tr '[A-Z]' '[a-z]' |  \ 
> sed -e "s/\t/ /g;s/\`//g;s/(.*$//;s/ set .*$//;s/ as .*$//" | sed -e "s/ where .*$//" |  \ 
> sort | uniq -c | sort -nr 
      7 insert into tab02 values 
      2 update tab02 
      1 delete from tab02 

相关阅读:

MySQL 大DML操作建议 http://www.linuxidc.com/Linux/2013-08/88235.htm

MySQL常用DDL、DML、DCL语言整理(附样例) http://www.linuxidc.com/Linux/2013-06/86431.htm

MySQL中binlog日记清理 http://www.linuxidc.com/Linux/2011-02/32017.htm

linux
相关资讯       MySQL binlog  DML语句 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款