Heim  >  Artikel  >  Datenbank  >  So importieren Sie alle MySQL-Tabellendaten in die Clichhouse-Bibliothek

So importieren Sie alle MySQL-Tabellendaten in die Clichhouse-Bibliothek

王林
王林nach vorne
2023-05-27 19:31:341139Durchsuche

1. Umgebung

  • tidb06 mysql5.7.32

  • tidb05 clickhouse20.8.3.1 8 # 🎜🎜#

2. Erstellen Sie eine Testbibliothekstabelle und schreiben Sie Testdaten

tidb06 Bibliothek erstellt ein Kopierkonto: #🎜🎜 #

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-Bibliothek erstellt die Testbibliothekstabelle test01.tb2 und schreibt Testdaten:

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-Bibliothekstabellenerstellungsmethode :

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');

Tipp:

clichhouse-Tabelle muss mindestens ein Zeitfeld enthalten

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.

Das obige ist der detaillierte Inhalt vonSo importieren Sie alle MySQL-Tabellendaten in die Clichhouse-Bibliothek. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:yisu.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen