首頁 > 軟體

將MySQL的表資料全量匯入clichhouse庫中

2022-03-21 16:02:04

一、環境

  • 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庫中內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com