Code Monkey home page Code Monkey logo

mysql2ch's Introduction

mysql2ch

https://img.shields.io/pypi/v/mysql2ch.svg?style=flat https://img.shields.io/docker/cloud/build/long2ice/mysql2ch https://img.shields.io/github/license/long2ice/mysql2ch

Introduction

mysql2ch is used to sync data from MySQL to ClickHouse.

https://github.com/long2ice/mysql2ch/raw/master/images/mysql2ch.png

Requirements

  • kafka
  • docker & docker-compose

Usage

Full data etl

$ mysql2ch etl -h

usage: mysql2ch etl [-h] --schema SCHEMA --tables TABLES [--renew]

optional arguments:
  -h, --help       show this help message and exit
  --schema SCHEMA  Schema to full etl.
  --tables TABLES  Tables to full etl,multiple tables split with comma.
  --renew          Etl after try to drop the target tables.

Continuous Sync

  1. cp .env.example .env and edit it.
  2. edit docker-compose.yml,which will read .env,add your own consumer services in docker-compose.yml.One consumer consume one kafka partition.
  3. docker-compose up -d.

Note

When one service consume multiple partitions,consumer commit maybe incorrect when insert error.

Optional

Sentry,error reporting,worked if set SENTRY_DSN in .env.

Example

.env

# if True,will display sql information
DEBUG=True
# sentry need
ENVIRONMENT=development

MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=123456
MYSQL_SERVER_ID=101

REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0

CLICKHOUSE_HOST=127.0.0.1
CLICKHOUSE_PORT=9002
CLICKHOUSE_PASSWORD=
CLICKHOUSE_USER=default

SENTRY_DSN=https://[email protected]/1

KAFKA_SERVER=127.0.0.1:9092
KAFKA_TOPIC=mysql2ch

# only these schemas to replication,multiple split with comma.
SCHEMAS=test
# only these tables to replication,multiple split with comma.
TABLES=test

# kafka partitions mapping,which means binlog of test.test will produce to 0 partition.
PARTITIONS=test.test=0;test.test2=1;

# init binlog file and position,should set first,after will read from redis.
INIT_BINLOG_FILE=binlog.000474
INIT_BINLOG_POS=155

# how many num to submit
INSERT_NUMS=20000
# how many seconds to submit
INSERT_INTERVAL=60

docker-compose.yml

version: '3'
services:
  producer:
    env_file:
      - .env
    depends_on:
      - redis
    image: long2ice/mysql2ch:latest
    command: mysql2ch produce
  # add more service if you need.
  consumer.test.test:
    env_file:
      - .env
    depends_on:
      - redis
      - producer
    image: long2ice/mysql2ch:latest
    # consume binlog of test.test
    command: mysql2ch consume --schema test --tables test
  redis:
    hostname: redis
    image: redis:latest
    volumes:
      - redis:/data
volumes:
  redis:

mysql2ch's People

Contributors

long2ice avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.