当前位置:网站首页>Clickhouse deployment and basic usage 1

Clickhouse deployment and basic usage 1

2022-06-24 11:07:00 Tdsql-a assistant

1. Deployment structure

stay Clickhouse in , In general, there are 2 There are two ways to deploy ,3 Method of use :

clickhouse Deployment structure .png

Deployment way :

  • Deployment way 1: Deploy a single node Clickhouse colony , For example, the cluster used by Xiaobai .
  • Deployment way 2: Deploy a multi node cluster , such as Tom and Jim Cluster used

Usage mode :

  • Usage mode 1: Single node cluster , Single node execution SQL Direct manipulation . For example, Xiaobai in the above figure (sql No middle on cluster sentence )
  • Usage mode 2:: Multi node cluster , And how to use it 1 equally , Like the one above Tom(sql No middle on cluster sentence ) This way, , If the user is connected to Different nodes What you see The data may be different Of .
  • Usage mode 3: Multi node cluster , user Cluster operation , Like the one above Sam and Jim Cluster operation , SQL Statement needs to be added on cluster XXXX, XXX Indicates the cluster name .

The following is a brief introduction to the basic functions of cluster operation and single node operation SQL.

2. Cluster operation Demo SQL

  • 2.1 Create a database
create database db_test on cluster default_cluster
  • 2.2. Delete a database
drop database db_test on cluster default_cluster
  • 2.3. Create a table
CREATE TABLE db_test.tbl_replac_merge_test on cluster default_cluster
(
 id String, 
 code String, 
 create_time DateTime
)
ENGINE = ReplacingMergeTree()
PARTITION BY toYYYYMM(create_time)
PRIMARY KEY id
ORDER BY (id, code);
  • 2.4. Delete a table
drop table db_test.tbl_replac_merge_test on cluster default_cluster

3. Single node operation Demo SQL

  • 3.1. Create a database
create database db_test;
  • 3.2. Delete a database
drop database db_test;
  • 3.3. Create a table
CREATE TABLE db_test.tbl_replac_merge_test
(
`id` String, 
`code` String, 
`create_time` DateTime
)
ENGINE = ReplacingMergeTree()
PARTITION BY toYYYYMM(create_time)
PRIMARY KEY id
ORDER BY (id, code);

  • 3.4. Delete a database table
drop table db_tetbl_replac_merge_test

4. How to create distributed tables and local tables

  • 4.1 Create database
CREATE DATABASE db_100 on cluster default_cluster;
  • 4.2 Create local table
CREATE TABLE db_100.tb_1_local on cluster default_cluster
(
    `c1` Int64,
    `c2` String,
    `_sign` Int8,
    `_version` UInt64
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/5a165fe5-ab38-4bf2-a6ee-5124a65ed1aa/{shard}', '{replica}', _version)
ORDER BY (c1, c2)
SETTINGS index_granularity = 8192
  • 4.3 Create a distributed table
CREATE TABLE db_100.tb_1 on cluster default_cluster
(
    `c1` Int64,
    `c2` String,
    `_sign` Int8,
    `_version` UInt64
)
ENGINE = Distributed('default_cluster', 'db_1', 'tb_1_local', cityHash64(toString((c1, c2))))


more Clickhouse Table creation document :

https://clickhouse.tech/docs/en/sql-reference/statements/create/table/

原网站

版权声明
本文为[Tdsql-a assistant]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/06/20210607002236697M.html