■ 빠른 설치

-- 설치 폴더 생성
# mkdir /data
# cd data

-- 설치 스크립트 다운로드
# curl https://clickhouse.com/ | sh
...
Successfully downloaded the ClickHouse binary, you can run it as:
    ./clickhouse

You can also install it:
    sudo ./clickhouse install

-- Clickhouse 설치
# ./clickhouse install
...
ClickHouse has been successfully installed.

Start clickhouse-server with:
 sudo clickhouse start

Start clickhouse-client with:
 clickhouse-client --password

 

■ Clickhouse 시작/상태확인/중지

-- Clickhouse 시작
# clickhouse start
...
Waiting for server to start
Waiting for server to start
Server started

-- Clickhouse 상태 확인
# clickhouse status
# /var/run/clickhouse-server/clickhouse-server.pid file exists and contains pid = 4745.
The process with pid = 4745 is running.

-- Clickhouse pid 확인
# ll /var/run/clickhouse-server/
합계 4

-rw-r-----. 1 clickhouse clickhouse 4  7월 28 20:35 clickhouse-server.pid

 

■ Clickhouse 서버 연결

# clickhouse client
...
:) select 1;

SELECT 1

Query id: 664ba0f1-ef35-4956-899e-fa922642746b

   ┌─1─┐

1. │ 1 │

   └───┘

1 row in set. Elapsed: 0.001 sec.

 

■ 테이블 생성

:) CREATE TABLE my_first_table
(
    user_id UInt32,
    message String,
    timestamp DateTime,
    metric Float32
)
ENGINE = MergeTree
PRIMARY KEY (user_id, timestamp);

Query id: c94b3468-4ba9-44ff-8a94-0b2dc55c59a9

Ok.

0 rows in set. Elapsed: 0.037 sec. 

 

■ 데이터 입력

:) INSERT INTO my_first_table (user_id, message, timestamp, metric) VALUES
    (101, 'Hello, ClickHouse!',                                 now(),       -1.0    ),
    (102, 'Insert a lot of rows per batch',                     yesterday(), 1.41421 ),
    (102, 'Sort your data based on your commonly-used queries', today(),     2.718   ),
    (101, 'Granules are the smallest chunks of data read',      now() + 5,   3.14159 );

INSERT INTO my_first_table (user_id, message, timestamp, metric) FORMAT Values

Query id: a631909c-f7c0-4fa4-a76a-79dc7aced796

Ok.

4 rows in set. Elapsed: 0.005 sec.

 

■ 데이터 조회

:) SELECT *
 FROM my_first_table
ORDER BY timestamp;

SELECT *
FROM my_first_table
ORDER BY timestamp ASC

Query id: d770d66c-18e1-45d9-b0e0-cd17f3c422f4

   ┌─user_id─┬─message───────────────────┬───────────timestamp─┬──metric─┐

1. │     102 │ Insert a lot of rows per batch                     │ 2024-07-27 00:00:00 │ 1.41421 │

2. │     102 │ Sort your data based on your commonly-used queries │ 2024-07-28 00:00:00 │   2.718 │

3. │     101 │ Hello, ClickHouse!                                 │ 2024-07-28 20:50:23 │      -1 │

4. │     101 │ Granules are the smallest chunks of data read      │ 2024-07-28 20:50:28 │ 3.14159 │

   └─────────┴────────────────────┴─────────────────────┴─────────┘

4 rows in set. Elapsed: 0.001 sec. 

 


※ Referneces

+ Recent posts