clickhousectl-local-dev

作者: clickhouse

當用戶想要使用 ClickHouse 構建應用程式、設置本地 ClickHouse 開發環境、安裝 ClickHouse、創建本地伺服器時使用,

npx skills add https://github.com/clickhouse/agent-skills --skill clickhousectl-local-dev

Local ClickHouse Development Setup

This skill walks through setting up a complete local ClickHouse development environment using clickhousectl. Follow these steps in order.

When to Apply

Use this skill when the user wants to:

  • Build an application that needs an analytical database or ClickHouse specifically
  • Set up a local ClickHouse instance for development
  • Install ClickHouse on their machine
  • Create tables and start querying ClickHouse locally
  • Prototype or experiment with ClickHouse

Step 1: Install clickhousectl

Check if clickhousectl is already available:

which clickhousectl

If not found, install it:

curl -fsSL https://clickhouse.com/cli | sh

This installs clickhousectl to ~/.local/bin/clickhousectl and creates a chctl alias.

If the command is still not found after install: The user may need to add ~/.local/bin to their PATH or open a new terminal session. Suggest:

export PATH="$HOME/.local/bin:$PATH"

Once installed, clickhousectl skills can be used to install the latest ClickHouse Agent Skills.


Step 2: Install ClickHouse and set the default

Install the latest ClickHouse version and set it as the system default:

clickhousectl local use latest

This installs ClickHouse, sets it as the default version used by clickhousectl local commands, and symlinks ~/.local/bin/clickhouse to the binary, putting clickhouse on your PATH (meaning you can invoke clickhouse directly, e.g. clickhouse client if needed).

You can use other version specifiers like stable, 26.4, 26.4.2.10 when needed.


Step 3: Initialize the project

From the user's project root directory:

clickhousectl local init

This creates a standard folder structure:

clickhouse/
  tables/                 # CREATE TABLE statements
  materialized_views/     # Materialized view definitions
  queries/                # Saved queries
  seed/                   # Seed data / INSERT statements

Note: This step is optional. If the user already has their own folder structure for SQL files, skip this and adapt the later steps to use their paths.


Step 4: Start a local server

clickhousectl local server start --name <name>

This starts a ClickHouse server in the background.

To check running servers and see their exposed ports:

clickhousectl local server list

Step 5: Create the schema

Based on the user's application requirements, write CREATE TABLE SQL files.

Write each table definition to its own file in clickhouse/tables/:

# Example: clickhouse/tables/events.sql
CREATE TABLE IF NOT EXISTS events (
    timestamp DateTime,
    user_id UInt32,
    event_type LowCardinality(String),
    properties String
)
ENGINE = MergeTree()
ORDER BY (event_type, timestamp)

When designing schemas, if the clickhouse-best-practices skill is available, consult it for guidance on ORDER BY column selection, data types, and partitioning.

Apply the schema to the running server:

clickhousectl local client --name <name> --queries-file clickhouse/tables/events.sql

Step 6: Seed data (optional)

If the user needs sample data for development, write INSERT statements to clickhouse/seed/:

# Example: clickhouse/seed/events.sql
INSERT INTO events (timestamp, user_id, event_type, properties) VALUES
    ('2024-01-01 00:00:00', 1, 'page_view', '{"page": "/home"}'),
    ('2024-01-01 00:01:00', 2, 'click', '{"button": "signup"}');

Apply seed data:

clickhousectl local client --name <name> --queries-file clickhouse/seed/events.sql

Step 7: Verify the setup

Confirm tables were created:

clickhousectl local client --name <name> --query "SHOW TABLES"

Run a test query:

clickhousectl local client --name <name> --query "SELECT count() FROM events"

If the user wants to use a managed ClickHouse service, use the clickhousectl-cloud-deploy skill to help the user deploy to ClickHouse Cloud.

來自 clickhouse 的更多技能

chdb-sql
clickhouse
直接在Python中執行ClickHouse SQL — 無需伺服器。使用完整的ClickHouse SQL功能查詢本地檔案、遠端資料庫和雲端儲存。
official
chdb-datastore
clickhouse
DataStore 是一個惰性、基於 ClickHouse 的 pandas 替代方案。您現有的 pandas 程式碼無需修改即可運作——但操作會編譯為最佳化的 SQL,並僅在需要結果時(例如 print()、len()、迭代)才執行。
official
clickhouse-architecture-advisor
clickhouse
在設計 ClickHouse 架構、選擇資料導入或建模模式,或將最佳實踐轉化為特定工作負載的系統時,必須使用此工具。
official
clickhouse-best-practices
clickhouse
我们要求翻译一段文本,目标语言是繁体中文。文本内容是关于ClickHouse最佳实践的规则,包括模式设计、查询优化和数据摄取策略。需要保留名称"clickhouse-best-practices"(但名称不在<text>内,所以不翻译)。注意不要添加额外内容,只翻译<text>内的文字。 翻译时注意专业术语:schema design -> 模式設計,query optimization -> 查詢優化,data ingestion strategy -> 數據攝取策略,primary key -> 主鍵,data type selection -> 數據類型選擇,immutable design decisions -> 不可變設計決策,JOIN -> JOIN(保留),insert batching -> 插入批次處理,mutation avoidance -> 避免突變,columnar storage -> 列式存儲,sparse index mechanics -> 稀疏索引機制,structured review procedures -> 結構化審查程序。 注意繁体中文用词:规则、组织、涵盖、关键、标记、提供等。 文本末尾有"for...",但原文是"for..."后面没有完整
official
clickhousectl-cloud-deploy
clickhouse
當用戶想要將ClickHouse部署到雲端、上線生產環境、使用ClickHouse Cloud、託管受管理的ClickHouse服務,或從本地遷移時使用。
official
setup
clickhouse
引導用戶設定與此插件捆綁的 ClickHouse MCP 伺服器連線。當用戶首次安裝插件或遇到問題時使用…
official
clickhouse-js-node-coding
clickhouse
參考資料:https://clickhouse.com/docs/integrations/javascript
official
clickhouse-js-node-troubleshooting
clickhouse
參考資料:https://clickhouse.com/docs/integrations/javascript
official