Go 两数相除
11个月前
docker下streamsets 同步 Mysql到clickhouse最详细部署,珍爱生命,少走弯路!
首先使用docker安装 Mysql:
docker pull mysql:latest
然后安装Clickhouse:
docker pull yandex/clickhouse-server:8.0.21
安装完成后启动Clickhouse:
docker run -d --name ch-server --ulimit nofile=262144:262144 -p 8123:8123 -p 9000:9000 -p 9009:9009 yandex/clickhouse-server
安装完成后启动Mysql:
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -v $(pwd)/mysql8:/var/lib/mysql -d mysql:8.0.21
执行命令:
docker ps
使用复制下来的容器ID 进入Mysql容器:
docker exec -it 7e47ac850a63 /bin/bash
导入测试数据:
CREATE DATABASE datacenter; USE datacenter; DROP TABLE IF EXISTS `base_member`; CREATE TABLE `base_member` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT '用户id', `username` varchar(20) NOT NULL COMMENT '帐号', `password` varchar(50) NOT NULL COMMENT '密码', `salt` varchar(50) NOT NULL COMMENT '密码加盐', `mobile` varchar(20) NOT NULL COMMENT '手机号', `icard` varchar(50) DEFAULT NULL COMMENT '身份证号码', `realname` varchar(20) NOT NULL COMMENT '真实姓名', `status` int NOT NULL COMMENT '状态', `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `deleted_at` datetime(3) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `mobile_index` (`mobile`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='中台用户表'; INSERT INTO `base_member` VALUES (5, '', '666666', '', '19988888881', '', '', 0, '2021-10-16 08:53:15', '2021-10-16 08:53:15', '1970-01-01 08:00:00.000'); INSERT INTO `base_member` VALUES (6, '', '666666', '', '19911888881', '', '', 0, '2021-10-16 08:54:34', '2021-10-16 08:54:34', '1970-01-01 08:00:00.000'); INSERT INTO `base_member` VALUES (7, '', '666666', '', '19911818881', '', '', 0, '2021-10-16 08:56:40', '2021-10-16 08:56:40', '1970-01-01 08:00:00.000'); INSERT INTO `base_member` VALUES (8, '', '666666', '', '19911818981', '', '', 0, '2021-10-16 08:56:46', '2021-10-16 08:56:46', '1970-01-01 08:00:00.000'); INSERT INTO `base_member` VALUES (9, '', '666666', '', '12911818981', '', '', 0, '2021-10-16 08:56:58', '2021-10-16 08:56:58', '1970-01-01 08:00:00.000'); INSERT INTO `base_member` VALUES (10, '', '666666', '', '12911828981', '', '', 0, '2022-10-16 09:09:09', '2021-10-16 10:00:55', '1970-01-01 08:00:00.000'); INSERT INTO `base_member` VALUES (11, '', '666666', '', '12911838981', '', '', 0, '2021-10-16 09:09:09', '2021-10-16 09:57:35', '1970-01-01 08:00:00.000');
使用复制下来的容器ID 进入Clickhouse容器:
docker exec -it 9f8328ca1d7c /bin/bash
新建测试表:
create database datacenter; use datacenter; create table base_member1( id Int32,username String, password String,salt String, mobile String,icard String, realname String,status Int32, update_time DATETIME, deleted_at DATETIME, create_time DATETIME ) engine=Memory;
访问 streamsets:
可以参考:
创建一个Pipeline:
设置Mysql 账号密码:root admin
配置clickhouse 账号和密码 : default 123456
jdbc:clickhouse://192.168.33.210:8123/datacenter
上传jar扩展包:
百度网盘地址:MySQL和Clickhouse 的jar扩展包
提取码:fn8k
上传完扩展后,重启一下docker:
开启同步传输
如果出现:
MYSQL_003 - Error connecting to MySql: Client does not support authenticatio
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; FLUSH PRIVILEGES;
测试:
修改Mysql
USE datacenter; SELECT update_time FROM base_member WHERE id=5; UPDATE `base_member` SET update_time = '2022-01-01 12:00:00' WHERE id = 5; SELECT update_time FROM base_member WHERE id=5;
查看clickhouse:
留言簿