将MySQL的表数据全量导入clichhouse库中
吾爱主题
阅读:160
2024-04-01 23:23:46
评论:0
一、环境
- tidb06 mysql5.7.32
- tidb05 clickhouse20.8.3.18
二、创建测试库表写入测试数据
tidb06库创建复制账户:
?1 2 | 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并且写入测试数据:
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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库的建表创建方法:
?1 | 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表中要求必须至少包含一个时间字段
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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库中内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.51cto.com/wujianwei/3157528
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。