欢迎来到代码驿站!

Mysql

当前位置:首页 > 数据库 > Mysql

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

时间:2022-08-21 09:59:24|栏目:Mysql|点击:

一、环境

  • 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 缓存如何使用内存

栏    目:Mysql

下一篇:没有了

本文标题:将MySQL的表数据全量导入clichhouse库中

本文地址:http://www.codeinn.net/misctech/211444.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有