All Projects → zalora → Binlog Parser

zalora / Binlog Parser

Licence: mit
A parser for MySQL binlog files that creates JSON messages. Useful for creating a stream of database events that can be stored and analyzed.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Binlog Parser

Supermarket
设计精良的网上商城系统,包括前端、后端、数据库、负载均衡、数据库缓存、分库分表、读写分离、全文检索、消息队列等,使用SpringCloud框架,基于Java开发。该项目可部署到服务器上,不断完善中……
Stars: ✭ 1,278 (+1274.19%)
Mutual labels:  mysql
Incepiton Mysql
🍭A web platform designed for mysql inception
Stars: ✭ 90 (-3.23%)
Mutual labels:  mysql
Drc
MySQL active-active replication solution.
Stars: ✭ 92 (-1.08%)
Mutual labels:  mysql
Bootplus
基于SpringBoot + Shiro + MyBatisPlus的权限管理框架
Stars: ✭ 88 (-5.38%)
Mutual labels:  mysql
Springboot Registration Login Theperfectexample
Login & Signup tutorial for every website ,mixes a lot of microservices together with the latest spring framework api in combined with full security
Stars: ✭ 89 (-4.3%)
Mutual labels:  mysql
Docker Symfony
🐳 A docker multicontainer with NGINX, PHP7-FPM, MySQL and ELK (Elasticsearch Logstash and Kibana)
Stars: ✭ 1,305 (+1303.23%)
Mutual labels:  mysql
Go Id Builder
这是一个ID生成器,它可以提供通过高效的方式产生连续的唯一的ID值。在分库分表时可以提供非常有用的帮助。
Stars: ✭ 87 (-6.45%)
Mutual labels:  mysql
Docker Librenms
Docker image for LibreNMS
Stars: ✭ 91 (-2.15%)
Mutual labels:  mysql
Freeacs
(Seeking maintainer) Free TR-069 ACS that can run (mostly) anywhere.
Stars: ✭ 90 (-3.23%)
Mutual labels:  mysql
Reactjs Spring Boot Crud Full Stack App
Learn how to develop a full-stack CRUD application using React as frontend and spring boot as backend.
Stars: ✭ 90 (-3.23%)
Mutual labels:  mysql
Docker Series
Docker Series about containerizing ASP.NET Core app with MySQL..
Stars: ✭ 88 (-5.38%)
Mutual labels:  mysql
Docker Compose Lamp
A basic LAMP stack environment built using Docker Compose.
Stars: ✭ 1,284 (+1280.65%)
Mutual labels:  mysql
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+19435.48%)
Mutual labels:  mysql
Docker springboot tomcat mysql demo
How to setup docker with SpringBoot on Tomcat and MySQL
Stars: ✭ 88 (-5.38%)
Mutual labels:  mysql
Fizz
A Common DSL for Migrating Databases
Stars: ✭ 92 (-1.08%)
Mutual labels:  mysql
Go Sniffer
🔎Sniffing and parsing mysql,redis,http,mongodb etc protocol. 抓包截取项目中的数据库请求并解析成相应的语句。
Stars: ✭ 1,281 (+1277.42%)
Mutual labels:  mysql
Dockerweb
A docker-powered bash script for shared web hosting management. The ultimate Docker LAMP/LEMP Stack.
Stars: ✭ 89 (-4.3%)
Mutual labels:  mysql
Good Articles By Sort
本仓库用来存放我看过的认为比较好的文章---根据分类排序
Stars: ✭ 93 (+0%)
Mutual labels:  mysql
Zhihuspider
知乎用户公开个人信息爬虫, 能够爬取用户关注关系,基于Python、使用代理、多线程
Stars: ✭ 92 (-1.08%)
Mutual labels:  mysql
Scm Biz Suite
供应链中台系统基础版,集成零售管理, 电子商务, 供应链管理, 财务管理, 车队管理, 仓库管理, 人员管理, 产品管理, 订单管理, 会员管理, 连锁店管理, 加盟管理, 前端React/Ant Design, 后端Java Spring+自有开源框架,全面支持MySQL, PostgreSQL, 全面支持国产数据库南大通用GBase 8s,通过REST接口调用,前后端完全分离。
Stars: ✭ 1,310 (+1308.6%)
Mutual labels:  mysql

binlog-parser

Build Status

A tool for parsing a MySQL binlog file to JSON. Reads a binlog input file, queries a database for field names, writes JSON to stdout. The output looks like this:

{
    "Header": {
        "Schema": "test_db",
        "Table": "buildings",
        "BinlogMessageTime": "2017-04-13T06:34:30Z",
        "BinlogPosition": 397,
        "XId": 9
    },
    "Type": "Insert",
    "Data": {
        "Row": {
            "address": "3950 North 1st Street CA 95134",
            "building_name": "ACME Headquaters",
            "building_no": 1
        },
        "MappingNotice": ""
    }
}
...

Installation

Requires Go version 1.7 or higher.

$ git clone https://github.com/zalora/binlog-parser.git
$ cd binlog-parser
$ git submodule update --init
$ make
$ ./bin/binlog-parser -h

Assumptions

  • It is assumed that MySQL row-based binlog format is used (or mixed, but be aware, that then only the row-formatted data in mixed binlogs can be extracted)
  • This tool is written with MySQL 5.6 in mind, although it should also work for MariaDB when GTIDs are not used

Usage

Run binlog-parser -h to get the list of available options:

Usage:	binlog-parser [options ...] binlog

Options are:

  -alsologtostderr
    	log to standard error as well as files
  -include_schemas string
    	comma-separated list of schemas to include
  -include_tables string
    	comma-separated list of tables to include
  -log_backtrace_at value
    	when logging hits line file:N, emit a stack trace
  -log_dir string
    	If non-empty, write log files in this directory
  -logtostderr
    	log to standard error instead of files
  -prettyprint
    	Pretty print json
  -stderrthreshold value
    	logs at or above this threshold go to stderr
  -v value
    	log level for V logs
  -vmodule value
    	comma-separated list of pattern=N settings for file-filtered logging

Required environment variables:

DB_DSN	 Database connection string, needs read access to information_schema

Example usage

Using dbuser and no password, connecting to information_schema database on localhost, parsing the binlog file /some/binlog.bin:

[email protected]/information_schema ./binlog-parser /some/binlog.bin

Matching field names and data

The mysql binlog format doesn't include the fieldnames for row events (INSERT/UPDATE/DELETE). As the goal of the parser is to output usable JSON, it connects to a running MySQL instance and queries the information_schema database for information on field names in the table.

The database connection is creatd by using the environment variable DB_DSN, which should contain the database credentials in the form of user:[email protected]/dbname - the format that the Go MySQL driver uses.

Effect of schema changes

As this tool doesn't keep an internal representation of the database schema, it is very well possible that the database schema and the schema used in the queries in the binlog file already have diverged (e. g. parsing a binlog file from a few days ago, but the schema on the main database already changed by dropping or adding columns).

The parser will NOT make an attempt to map data to fields in a table if the information schema retuns more or too less columns compared to the format found in the binlog. The field names will be mapped as "unknown":

{
    "Header": {
        "Schema": "test_db",
        "Table": "employees",
        "BinlogMessageTime": "2017-04-13T08:02:04Z",
        "BinlogPosition": 635,
        "XId": 8
    },
    "Type": "Insert",
    "Data": {
        "Row": {
            "(unknown_0)": 1,
            "(unknown_1)": "2017-04-13",
            "(unknown_2)": "Max",
            "(unknown_3)": "Mustermann"
        },
        "MappingNotice": "column names array is missing field(s), will map them as unknown_*"
    }
}

More complex case

Changing the order of fields in a table can lead to unexpected parser results. Consider an example binlog file A.bin. A query like INSERT INTO db.foo SET field_1 = 10, field_2 = 20 will look in the binlog like this:

...
### INSERT INTO `db`.`foo`
### SET
###   @1=20 /* ... */
###   @2=20 /* ... */
...

The parser queries information_schema for the field names of the db.foo table:

+-------------+-----+
| Field       | ... |
+-------------+-----+
| field_1     | ... |
| field_2     | ... |
+-------------+-----+

The fields will be mapped by the parser in the order as specified in the table and the JSON will look like this:

{
    ...
    "Type": "Insert",
    "Data": {
        "Row": {
            "field_1": 10,
            "field_2": 20
        }
    }
}
...

Now if a schema change happened after some time, db.foo fields might look now like this (the order of the fiels changed):

+-------------+-----+
| Field       | ... |
+-------------+-----+
| field_2     | ... |
| field_1     | ... |
+-------------+-----+

If you parse the same binlog file A.bin now again, but against the new schema of db.foo (in which the fields changed position), the resulting JSON will look like that:

{
    ...
    "Type": "Insert",
    "Data": {
        "Row": {
            "field_2": 10,
            "field_1": 20
        }
    }
}
...

This means you have to be very careful when parsing old binlog files, as the db schema can have evolved since the binlog was generated and the parser has no way of knowing of these changes.

If this limitation is not acceptable, some tools like Maxwell's Daemon by Zendesk can work around that issue at the cost of greater complexity.

Releases

How to do a release:

git tag -a X.X.X -m "... release note ..."
git push --follow-tags

Travis CI will attach a statically built binary to the release tag on GitHub.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].