(20210303)docker clickhouse 初阶使用

  • Overview

    文中大部分内容都可以从官方docs中找到,这里只是以docker为主线梳理细分领域的操作。

  • 安装

    官方image

    可能遇到的问题:

    (20210302已解决)docker启动clickhouseInclude not found clickhouse_remote_servers

    (20210302已解决)WARNING Found orphan containers for this project

    (20210302已解决)clickhouse docker, as it does not belong to the default network

    理解Creating network “projectName_default” with the default driver

  • 基本命令

    因为套了一层,因此docker container没有官方文档中的命令那么灵活。

    $ SHOW DATABASE;	# 查看有哪些数据库
    $ SHOW TABLES FROM databaseName	# 查看某数据库里有哪些表格
    $ DESCRIBE TABLE tableName		# 查看某表的schema, 只写表名默认是default.tableName
    $ DESCRIBE TABLE dbName.tableName
    $ SHOW CREATE TABLE dbName.tableName	# much more details of table
    
    # ****************Database**********************
    $ CREATE DATABASE IF NOT EXISTS tutorial	# 创建
    $ SHOW DATABASES							# 查看
    $ DESCRIBE TABLE db.table 
    # ****************Tables************************
    $ CREATE TABLE tutorial.nestedt ( `id` UInt8, `aux` Nested(a UInt8, b String))ENGINE=TinyLog
    # ****************Import Data*******************
    $ INSERT INTO tutorial.nestedt Values (1, [1], ['a'])
    # ****************Select Data*******************
    $ SELECT * FROM tutorial.nestedt FORMAT TSV
    $ SELECT COUNT(*) FROM tutorial.nestedt
    # ****************Settings**********************
    $ SELECT name,value, changed, description FROM system.settings WHERE name LIKE '%max_insert_b%' FORMAT TSV	# 查看设置
    # ****************Optimize**********************
    $ OPTIMIZE TABLE tutorial.nestedt FINAL
    
  • create table

    Syntax for creating tables is way m ore complicated compared to databases. In general CREATE TABLE statement has to specify three key things:

    • Name of table to create
    • Table schema, i.e. list of columns and their data types
    • Table engine and its setting, which determines all the details on how queries to this table will physically executed
  • References

  1. ClickHouse Docs

猜你喜欢

转载自blog.csdn.net/The_Time_Runner/article/details/114434814