Skip to content

quanwei888/mysqlq

Repository files navigation

==========================================================
MysqlQ - Mysql Row Changce Callback Service over MemcacheQ
==========================================================

*** bata阶段,还有bug ***
简介
=========
* mysqlq基于memcacheq开发,同步mysql主库的binglog事件(基于row-based复制模式),将变化的数据行顺序加入以MYSQL_EVENT为名的队列,客户端以memcacheq协议来取队列中的数据。

快速开始
===============

下载
---------
See: <https://github.com/quanwei888/mysqlq>

安装依赖
-------------
* Berkeley DB 4.7 or later
* libevent 1.4.x or later
* libmysqlclient 5.0 or later

安装
-------------
./configure --prefix=<PREFIX> --with-libevent=<LIBEVENT-DIR> --with-bdb=<BDB-DIR> --with-mysql=<MYSQL_DIR>
make
make install
启动
-------------
./mysqlq --mysql-host=127.0.0.1 --mysql-port==3306 --mysql-user=root --mysql-password=123456

参数说明
-------------
--mysql-host=<host>            master mysql host,default is '127.0.0.1'
--mysql-port=<port>            master mysql port,default is 3306
--mysql-user=<user>            master mysql user,default is 'root'
--mysql-password=<password>        master mysql password,default is empty
--mysql-serverid=<serverid>        master mysql serverid,default is 12345
--mysql-ralaypath=<ralaypath>  ralay path,default is '/tmp/ralay'


命令
---------
客户端仅需使用SET命令来取队列

**从mysqlq中取一条行变化数据**::

   get MYSQL_EVENT\r\n
   VALUE MYSQL_EVENT <flags> <message_len>\r\n
   <your message body will come here>\r\n
   END\r\n

数据格式
---------
队列中数据以JSON形式存放

* type:类型,int,2=增加,3=删除
* time:行变化的时间,int,时间戳
* table:行数据所属的表,string,"数据库名.表名"
* data:行数据,array(字段值),顺序同表中字段顺序

如在数据库中进行如下操作
************************************************************************************************
新建一张数据表
drop table if exists test.userinfo ;
create table test.userinfo 
(
	id int unsigned auto_increment primary key, 
	userName char(32) not null default '',
	password varchar(32) not null default '',
	description text not null default ''
)charset=utf8;

执行:insert into test.userinfo (userName,password,description) values('user1','111111','用户1');
队列中:{"type":2,"time":1353656040,"table":"test.userinfo","data":["1","user1","111111","用户1"]}

执行:insert into test.userinfo (userName,password,description) values('user2','111111','用户2');
队列中:{"type":2,"time":1353656082,"table":"test.userinfo","data":["2","user2","111111","用户2"]}

执行:delete from test.userinfo;
队列中:
{"type":3,"time":1353656108,"table":"test.userinfo","data":["1","user1","111111","用户1"]}
{"type":3,"time":1353656108,"table":"test.userinfo","data":["2","user2","111111","用户2"]}
************************************************************************************************

PHP Example
---------

  <?php
  /* connect to memcached server */
  $mysqlqClient = memcache_connect('127.0.0.1', 21201);

  /* consume a message from 'demoqueue1' */
  $event = memcache_get($mysqlqClient, 'MYSQL_EVENT');
  
  var_dump(json_decode($event,true));
  memcache_close($memcache_obj);
  ?>
  

About

Mysql Row Changce Callback Service over MemcacheQ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published