一、环境

  • tidb06 mysql5.7.32
  • tidb05 clickhouse20.8.3.18

二、创建测试库表写入测试数据

tidb06库创建复制账户:

grant select, replication slave, replication client on *.* to 'click_rep'@'172.16.0.246' identified by 'jwts996';flush privileges;
query ok, 0 rows affected, 1 warning (0.00 sec)

tidb06库创建测试库表test01.tb2并且写入测试数据:

create table `tb2` (
`id` int(8) not null auto_increment, 
`username` varchar(20) collate utf8_unicode_ci not null,
`password` varchar(20) collate utf8_unicode_ci not null, 
`create_time` datetime not null default current_timestamp comment '创建时间',
primary key (`id`) #主键id
) engine=innodb auto_increment=0 default charset=utf8 collate=utf8_unicode_ci;

insert into tb2(username,password,create_time) values('tomcat', 'xiaohuahua',now());
insert into tb2(username,password,create_time) values('java', 'xiaohuahua',now());
root@tidb06 14:01:  [test01]> select * from tb2;
+----+----------+------------+---------------------+
| id | username | password   | create_time         |
+----+----------+------------+---------------------+
|  1 | tomcat   | xiaohuahua | 2021-07-21 14:01:50 |
|  2 | java     | xiaohuahua | 2021-07-21 14:01:59 |
+----+----------+------------+---------------------+
2 rows in set (0.00 sec)

clickhouse库的建表创建方法:

create table tb2 engine = mergetree partition by toyyyymm(create_time) order by create_time as select * from mysql('172.16.0.247:3306', 'test01', 'tb2', 'click_rep', 'jwts996');

提示:clichhouse表中要求必须至少包含一个时间字段

tidb05 :) create table tb2 engine = mergetree partition by toyyyymm(create_time) order by create_time as select * from mysql('172.16.0.247:3306', 'test01', 'tb2', 'click_rep', 'jwts996');

create table tb2
engine = mergetree
partition by toyyyymm(create_time)
order by create_time as
select *
from mysql('172.16.0.247:3306', 'test01', 'tb2', 'click_rep', 'jwts996')

ok.

0 rows in set. elapsed: 0.014 sec. 

tidb05 :) select * from tb2;

select *
from tb2

┌─id─┬─username─┬─password───┬─────────create_time─┐
│  1 │ tomcat   │ xiaohuahua │ 2021-07-21 14:01:50 │
│  2 │ java     │ xiaohuahua │ 2021-07-21 14:01:59 │
└────┴──────────┴────────────┴─────────────────────┘

2 rows in set. elapsed: 0.002 sec. 

到此这篇关于将mysql的表数据全量导入clichhouse库中的文章就介绍到这了,更多相关mysql表数据导入clichhouse库中内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!