如何将MySQL的表数据全量导入clichhouse库中

网友投稿 488 2023-07-06

如何将MySQL的表数据全量导入clichhouse库中

如何将MySQL的表数据全量导入clichhouse库中

一、环境

tidb06 mysql5.7.32tidb05 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.登录后复制

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Linux系统下怎么删除MySQL
下一篇:mysql表怎么导出
相关文章