本文介绍了单节点集群和高可用的多节点集群创建ClickHouse数据表的方法

单节点集群

创建本地表

CREATE TABLE default.sls_test_single_local(
`v1` Int8, 
`v2` Int16, 
`v3` Int32, 
`v4` Int64, 
`v5` UInt8, 
`v6` UInt16, 
`v7` UInt32, 
`v8` UInt64, 
`v9` Decimal(10, 2), 
`v10` Float32, 
`v11` Float64, 
`v12` String, 
`v13` FixedString(10), 
`v14` UUID, `v15` Date, 
`v16` DateTime, 
`v17` Enum8('hello' = 1, 'world' = 2), 
`v18` Enum16('hello' = 1, 'world' = 2), 
`v19` IPv4, 
`v20` IPv6) 
ENGINE = MergeTree() PARTITION BY toYYYYMMDD(v16) ORDER BY v4 SETTINGS index_granularity = 8192;

高可用的多节点集群

  1. 创建本地表。
    CREATE TABLE default.sls_test_local ON CLUSTER default (
    `v1` Int8, 
    `v2` Int16, 
    `v3` Int32, 
    `v4` Int64, 
    `v5` UInt8, 
    `v6` UInt16, 
    `v7` UInt32, 
    `v8` UInt64, 
    `v9` Decimal(10, 2), 
    `v10` Float32, 
    `v11` Float64, 
    `v12` String, 
    `v13` FixedString(10), 
    `v14` UUID, `v15` Date, 
    `v16` DateTime, 
    `v17` Enum8('hello' = 1, 'world' = 2), 
    `v18` Enum16('hello' = 1, 'world' = 2), 
    `v19` IPv4, 
    `v20` IPv6) 
    ENGINE = ReplicatedMergeTree('/clickhouse/tables/sls_test_local/{shard}', '{replica}') 
    PARTITION BY toYYYYMMDD(v16) ORDER BY v4 SETTINGS index_granularity = 8192
  2. 创建分布式表,方便数据的写入和查询。
    CREATE TABLE sls_test_d ON CLUSTER default as sls_test_local ENGINE = Distributed(default, default, sls_test_local, rand());