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 tb2engine = mergetreepartition by toyyyymm(create_time)order by create_time asselect *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库中的详细内容。
