当前位置:网站首页>Clickhouse同步mysql(基于物化引擎)
Clickhouse同步mysql(基于物化引擎)
2022-07-05 03:33:00 【Younger成】
一、Mysql引擎(不推荐)
同步注意事项:1、库名规范不能有“-”,表名规范不能有“-”
CREATE DATABASE [IF NOT EXISTS] db_name [ON CLUSTER cluster]
ENGINE = MySQL('host:port', ['database' | database], 'user', 'password')
参数说明:
host:port
— MySQL服务地址database
— MySQL数据库名称user
— MySQL用户名password
— MySQL用户密码
MySQL引擎将远程的MySQL服务器中的表/库映射到ClickHouse中,MySQL数据库引擎会将对其的查询转换为MySQL语法并发送到MySQL服务器中(等同于直接使用mysql)
数据库同步:
CREATE DATABASE IF NOT EXISTS mysql_db ENGINE = MySQL ('localhost:3306', 'mysql', 'root', '123456');
表同步:
CREATE TABLE IF NOT EXISTS tmp ENGINE = MergeTree ORDER BY id AS SELECT * FROM mysql('localhost:3306','test','user','root','123456')
二、MaterializedMySQL(好用,但是官方还在实验阶段)
CREATE DATABASE [IF NOT EXISTS] db_name [ON CLUSTER cluster]
ENGINE = MaterializedMySQL('host:port', ['database' | database], 'user', 'password') [SETTINGS ...]
[TABLE OVERRIDE table1 (...), TABLE OVERRIDE table2 (...)]
创建ClickHouse数据库,包含MySQL中所有的表,以及这些表中的所有数据。
ClickHouse服务器作为MySQL副本工作。它读取binlog并执行DDL和DML查询
1、mysql开启binlog和GTID
vim /etc/mysql/my.cnf
[mysqld]
# 指定binlog日志存储位置
#log-bin=/data/logs/mysql/mysql-bin.log
log-bin=/var/lib/mysql/mysql-bin
# 开启GTID模式
gtid-mode=ON
# 设置主从强一致性
enforce-gtid-consistency=1
# 记录日志
log-slave-updates=1
binlog_format=ROW
2、创建复制管道
#开启物化引擎
SET allow_experimental_database_materialized_mysql=1;
CREATE DATABASE yfc
ENGINE = MaterializeMySQL('localhost:3306', 'yfc', 'root', '123456')
优点:通过监听mysql的binlog文件,实现增量更新,提升了效率
数据限制:
1、同步mysql数据之前,mysql的每张表应该都有primary key(如果没有主键,同步会报错)
2、MaterializedMySQL是库级别的引擎,同步的时候会以全库中表数据同步
3、mysql数据同步到clickhouse后会发生索引转换:在ClickHouse表中,MySQL的 PRIMARY KEY
和 INDEX
子句被转换为 ORDER BY
元组
4、mysql在转换为clickhouse表的时候,每张表都会新增两个字段:_sign(1:写入、-1:删除),_version
5、在clickhouse中同步新增时,并没有实现物理意义上的删除,只通过_sign标志字段来实现数据过滤
6、在mysql转化clickhouse时,默认使用的ReplacingMergeTree引擎,保证没有重复数据出现
实例:
#1、查询同步的数据库
show databses;
use yfc;
show tables;
#2、查看建表语句
show create table sku_info;
#3、查询同步的数据
select *,_sign,_version from sku_info;
#4、新增数据(往mysql的sku_info表中插入数据)
INSERT INTO `yfc`.`sku_info`(`id`, `sku_code`) VALUES (3, '10003');
#5、修改数据
UPDATE `yfc`.`ts_store_info` set cust_name = '连调测试' where id= 111;
#6、删除数据
DELETE FROM `yfc`.`sku_info` where id= 3;
三、mysql表函数
四、datax
边栏推荐
- Use of kubesphere configuration set (configmap)
- El tree whether leaf node or not, the drop-down button is permanent
- [安洵杯 2019]不是文件上传
- Is there any way to change the height of the uinavigationbar in the storyboard without using the UINavigationController?
- 1. Five layer network model
- Devtools的簡單使用
- 1.五层网络模型
- LeetCode 234. Palindrome linked list
- Multi person online anonymous chat room / private chat room source code / support the creation of multiple chat rooms at the same time
- Usage scenarios and solutions of ledger sharing
猜你喜欢
Zero foundation uses paddlepaddle to build lenet-5 network
SQL injection exercise -- sqli Labs
Ubantu disk expansion (VMware)
线程基础知识
Azkaban installation and deployment
Hot knowledge of multithreading (I): introduction to ThreadLocal and underlying principles
Yuancosmic ecological panorama [2022 latest]
error Couldn‘t find a package.json file in “你的路径“
Huawei MPLS experiment
【web审计-源码泄露】获取源码方法,利用工具
随机推荐
Delphi read / write JSON format
Machine learning experiment report 1 - linear model, decision tree, neural network part
Qrcode: generate QR code from text
LeetCode 237. Delete nodes in the linked list
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Devtools的簡單使用
天干地支纪年法中为什么是60年一个轮回,而不是120年
[groovy] string (string injection function | asBoolean | execute | minus)
Azkaban actual combat
Une question est de savoir si Flink SQL CDC peut définir le parallélisme. Si le parallélisme est supérieur à 1, il y aura un problème d'ordre?
How to make the listbox scroll automatically when adding a new item- How can I have a ListBox auto-scroll when a new item is added?
Solve the problem that sqlyog does not have a schema Designer
Flume configuration 4 - customize mysqlsource
Basic knowledge of tuples
[groovy] string (string splicing | multi line string)
Redis6-01nosql database
Use of kubesphere configuration set (configmap)
Clean up PHP session files
About MySQL database connection exceptions
【web审计-源码泄露】获取源码方法,利用工具