PHP Client for Mysql Binlog
PHP解析MySQL Binlog,依赖于mysql-replication-listener库
详见:https://github.com/bullsoft/php-binlog
Install MySQL Replication Listener
unzip mysql-replication-listener-master.zip
cd mysql-replication-listener-master
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-replication
make & make install
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
Install php-binlog
unzip php-binlog-master.zip
cd php-binlog-master/ext
/usr/local/php5.5.15/bin/phpize
./configure --with-php-config=/usr/local/php5.5.15/bin/php-config --with-mysql-binlog=/usr/local/mysql-replication
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
Examples
注:Binlog为行格式
<?php
$link = binlog_connect("mysql://root:cpyf@127.0.0.1:3306");
//binlog_set_position($link, 4);
//binlog_set_position($link, 4, 'mysql-bin.000006');
while($event=binlog_wait_for_next_event($link)) {
// it will block here
switch($event['type_code']) {
case BINLOG_DELETE_ROWS_EVENT:
var_dump($event);
// do what u want ...
break;
case BINLOG_WRITE_ROWS_EVENT:
var_dump($event);
// do what u want ...
break;
case BINLOG_UPDATE_ROWS_EVENT:
var_dump($event);
// do what u want ...
break;
default:
// var_dump($event);
break;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
Update_rows
update `type` set type_id = 22 WHERE id in (58, 59);
- 1
- 1
array(5) {
'type_code' =>
int(24)
'type_str' =>
string(11) "Update_rows"
'db_name' =>
string(5) "cloud"
'table_name' =>
string(4) "type"
'rows' =>
array(4) {
[0] =>
array(5) {
[0] =>
string(2) "58"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(2) "22"
[4] =>
string(1) "0"
}
[1] =>
array(5) {
[0] =>
string(2) "58"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(1) "4"
[4] =>
string(1) "0"
}
[2] =>
array(5) {
[0] =>
string(2) "59"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(2) "22"
[4] =>
string(1) "0"
}
[3] =>
array(5) {
[0] =>
string(2) "59"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(1) "4"
[4] =>
string(1) "0"
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
Delete_rows
delete from `type` WHERE id in (58, 59);
- 1
- 1
array(5) {
'type_code' =>
int(25)
'type_str' =>
string(11) "Delete_rows"
'db_name' =>
string(5) "cloud"
'table_name' =>
string(4) "type"
'rows' =>
array(2) {
[0] =>
array(5) {
[0] =>
string(2) "58"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(2) "22"
[4] =>
string(1) "0"
}
[1] =>
array(5) {
[0] =>
string(2) "59"
[1] =>
string(8) "adsfasdf"
[2] =>
string(4) "asdf"
[3] =>
string(2) "22"
[4] =>
string(1) "0"
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
Write_rows
insert into type values (Null, "Hello, World", "Best world", 4, 0), (NULL, "你好,世界", "世界很美好", 3, 5);
- 1
- 1
array(5) {
'type_code' =>
int(23)
'type_str' =>
string(10) "Write_rows"
'db_name' =>
string(5) "cloud"
'table_name' =>
string(4) "type"
'rows' =>
array(2) {
[0] =>
array(5) {
[0] =>
string(2) "95"
[1] =>
string(12) "Hello, World"
[2] =>
string(10) "Best world"
[3] =>
string(1) "4"
[4] =>
string(1) "0"
}
[1] =>
array(5) {
[0] =>
string(2) "96"
[1] =>
string(15) "你好,世界"
[2] =>
string(15) "世界很美好"
[3] =>
string(1) "3"
[4] =>
string(1) "5"
}
}
}
PHP Client for Mysql Binlog的更多相关文章
- MySQL Binlog 解析工具 Maxwell 详解
maxwell 简介 Maxwell是一个能实时读取MySQL二进制日志binlog,并生成 JSON 格式的消息,作为生产者发送给 Kafka,Kinesis.RabbitMQ.Redis.Goog ...
- 一个分布式 MySQL Binlog 存储系统的架构设计
1. kingbus简介 1.1 kingbus是什么? kingbus是一个基于raft强一致协议实现的分布式MySQL binlog 存储系统.它能够充当一个MySQL Slave从真正的Mast ...
- 20180705关于mysql binlog的解析方式
来自:https://blog.csdn.net/u012985132/article/details/74964366/ 关系型数据库和Hadoop生态的沟通越来越密集,时效要求也越来越高.本篇就来 ...
- 基于 MySQL Binlog 的 Elasticsearch 数据同步实践 原
一.背景 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品.订单等数据的多维度检索. 使用 Elasticsearch 存储业务数据可以 ...
- Canal - 数据同步 - 阿里巴巴 MySQL binlog 增量订阅&消费组件
背景 早期,阿里巴巴 B2B 公司因为存在杭州和美国双机房部署,存在跨机房同步的业务需求 ,主要是基于trigger的方式获取增量变更.从 2010 年开始,公司开始逐步尝试数据库日志解析,获取增量变 ...
- canal+kafka订阅Mysql binlog将数据异构到elasticsearch(或其他存储方式)
canal本质就是"冒充"从库,通过订阅mysql bin-log来获取数据库的更改信息. mysql配置(my.cnf) mysql需要配置my.cnf开启bin-log日志并且 ...
- 基于MySQL Binlog的Elasticsearch数据同步实践
一.为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品.订单等数据的多维度检索. 使用 Elasticsearch 存储业务数 ...
- MySql Binlog 说明 & Canal 集成MySql的更新异常说明 & MySql Binlog 常用命令汇总
文章来源于本人的印象笔记,如出现格式问题可访问该链接查看原文 原创声明:作者:Arnold.zhao 博客园地址:https://www.cnblogs.com/zh94 目录 背景介绍 开启MySq ...
- Canal实时解析mysql binlog数据实战
一.说明 通过canal实时监听mysql binlog日志文件的变化,并将数据解析出来 二.环境准备 1.创建maven项目并修改pom.xml配置文件 <dependencies> & ...
随机推荐
- idea中dependencies中总是有红色波浪线(缺少dependency)的解决办法
使用IDEA进行maven开发时,将新项目import进工作空间时,Maven Projects栏中的dependencies中总是有红色波浪线,如下图: 但是这些jar在我本地的maven仓库中实际 ...
- ZH奶酪:Ubuntu客户端通过SSH方式远程登录Ubuntu服务器
1.概述 传统的远程登录(telnet,rlogin)时不安全的,他们在网络上用明文传输口令和数据,SSH则是安全的,openssh提供两种级别的验证方式. (1)基于口令的安全验证:知道服务器的帐号 ...
- 微信小程序 - switchTab传值
“众所周知,switchTab是不能携带参数的” 我们有几种方式解决呢?(最好的解决方法是利用全局变量,这样可以避免因缓存造成的数据错误) 1. 通过全局变量(需要用到的页面都要引用它) 点击下载示例 ...
- C语言的角落——C之很常使用特性(一)
本文搜集整理了一些之前博客中没有提到的,C语言不经常使用的特性,算是对C系列的最后一次补充. 对C语言有兴趣的朋友能够浏览一下,查漏补缺. 变长參数列表 <stdarg.h> 头文件定义了 ...
- pushlet单播与多播
近期要弄一个消息推送的功能,在网上找了非常多的关于pushlet的文章,尽管写的都非常具体,可是本人看了以后却总认为是模棱两可···不知道怎样下手,终于參考了这些文章中的一些内容,并结合官网的源码.做 ...
- 怎么将txt文件转化为html格式的文件?--极为丑陋的方式
# -*- coding: utf-8 -*- #python 27 #xiaodeng #怎么将txt文件转化为html格式的文件?--极为丑陋的方式 import os #找出所有的txt格式的文 ...
- spring boot更换日志为log4j2
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- mysql利用yum安装指定数据存放路径
测试环境: Centos6.5.MySQL5.6.28 yum安装具有速度快,便捷关键是不用编译,编译时间太久了! 01.下载mysql https://mirrors.tuna.tsinghua.e ...
- 微信小程序裁剪图片成圆形
代码地址如下:http://www.demodashi.com/demo/14453.html 前言 最近在开发小程序,产品经理提了一个需求,要求微信小程序换头像,用户剪裁图片必须是圆形,也在gith ...
- 微信小程序基于swiper组件的tab切换
代码地址如下:http://www.demodashi.com/demo/14010.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...