ClickHouse Install & Auth
Overview
Set up the official ClickHouse client for Node.js or Python and configure authentication
to ClickHouse Cloud or a self-hosted instance.
Prerequisites
- Node.js 18+ or Python 3.8+
- A running ClickHouse instance (Cloud or self-hosted)
- Connection credentials (host, port, user, password)
Instructions
Step 1: Install the Official Client
# Node.js — official client (HTTP-based, supports streaming)
npm install @clickhouse/client
# Python — official client
pip install clickhouse-connect
Step 2: Configure Environment Variables
# .env (NEVER commit — add to .gitignore)
CLICKHOUSE_HOST=https://abc123.us-east-1.aws.clickhouse.cloud:8443
CLICKHOUSE_USER=default
CLICKHOUSE_PASSWORD=your-password-here
# Self-hosted (HTTP interface on port 8123, native on 9000)
# CLICKHOUSE_HOST=http://localhost:8123
Step 3: Create the Client (Node.js)
import { createClient } from '@clickhouse/client';
// ClickHouse Cloud
const client = createClient({
url: process.env.CLICKHOUSE_HOST, // https://<host>:8443
username: process.env.CLICKHOUSE_USER, // default
password: process.env.CLICKHOUSE_PASSWORD,
// ClickHouse Cloud requires TLS — the client handles it via https:// URL
});
// Self-hosted (no TLS)
const localClient = createClient({
url: 'http://localhost:8123',
username: 'default',
password: '',
});
Step 4: Verify Connection
async function verifyConnection() {
// Ping returns true if the server is reachable
const alive = await client.ping();
console.log('ClickHouse ping:', alive.success); // true
// Run a test query
const rs = await client.query({
query: 'SELECT version() AS ver, uptime() AS uptime_sec',
format: 'JSONEachRow',
});
const rows = await rs.json<{ ver: string; uptime_sec: number }>();
console.log('Server version:', rows[0].ver);
console.log('Uptime (sec):', rows[0].uptime_sec);
}
verifyConnection().catch(console.error);
Step 5: Python Alternative
import clickhouse_connect
client = clickhouse_connect.get_client(
host='abc123.us-east-1.aws.clickhouse.cloud',
port=8443,
username='default',
password='your-password-here',
secure=True,
)
result = client.query('SELECT version(), uptime()')
print(f"Version: {result.result_rows[0][0]}")
Connection Options Reference
| Option |
Default |
Description |
url |
http://localhost:8123 |
Full URL including protocol and port |
username |
default |
ClickHouse user |
password |
'' |
User password |
database |
default |
Default database for queries |
request_timeout |
30000 |
Query timeout in ms |
compression.request |
false |
Compress request bodies (gzip) |
compression.response |
true |
Decompress responses |
max_open_connections |
10 |
HTTP keep-alive pool size |
clickhouse_settings |
{} |
Server-side settings per session |
ClickHouse Cloud vs Self-Hosted
| Feature |
Cloud |
Self-Hosted |
| Port |
8443 (HTTPS) |
8123 (HTTP) / 8443 (HTTPS) |
| TLS |
Required |
Optional |
| Engine |
SharedMergeTree |
MergeTree family |
| Auth |
User/password, Cloud API keys |
User/password, LDAP, Kerberos |
Error Handling
| Error |
Cause |
Solution |
ECONNREFUSED |
Server not running |
Check host/port, verify ClickHouse is up |
Authentication failed |
Wrong user/password |
Verify credentials in ClickHouse users.xml or Cloud console |
CERTIFICATE_VERIFY_FAILED |
TLS mismatch |
Use https:// for Cloud, check CA certs for self-hosted |
TIMEOUT |
Network/firewall |
Check IP allowlists in Cloud console, firewall rules |
Database not found |
Wrong database name |
Run SHOW DATABASES to list available databases |
Resources
Next Steps
Proceed to clickhouse-hello-world for your first table and query.
1---
2name: clickhouse-install-auth
3description: |
4 Install @clickhouse/client and configure authentication to ClickHouse Cloud or self-hosted.
5 Use when setting up a new ClickHouse project, configuring connection strings,
6 or initializing the official Node.js client.
7 Trigger: "install clickhouse", "setup clickhouse client", "clickhouse auth",
8 "connect to clickhouse", "clickhouse credentials".
9allowed-tools: Read, Write, Edit, Bash(npm:*), Bash(pnpm:*), Bash(pip:*), Grep
10version: 1.0.0
11license: MIT
12author: Jeremy Longshore <jeremy@intentsolutions.io>
13tags: [saas, database, analytics, clickhouse, olap]
14compatible-with: claude-code
15metadata:
16 source: https://skillmd.com/skills/aibot88/clickhouse-install-auth
17---
18
19# ClickHouse Install & Auth
20
21## Overview
22
23Set up the official ClickHouse client for Node.js or Python and configure authentication
24to ClickHouse Cloud or a self-hosted instance.
25
26## Prerequisites
27
28- Node.js 18+ or Python 3.8+
29- A running ClickHouse instance (Cloud or self-hosted)
30- Connection credentials (host, port, user, password)
31
32## Instructions
33
34### Step 1: Install the Official Client
35
36```bash
37# Node.js — official client (HTTP-based, supports streaming)
38npm install @clickhouse/client
39
40# Python — official client
41pip install clickhouse-connect
42```
43
44### Step 2: Configure Environment Variables
45
46```bash
47# .env (NEVER commit — add to .gitignore)
48CLICKHOUSE_HOST=https://abc123.us-east-1.aws.clickhouse.cloud:8443
49CLICKHOUSE_USER=default
50CLICKHOUSE_PASSWORD=your-password-here
51
52# Self-hosted (HTTP interface on port 8123, native on 9000)
53# CLICKHOUSE_HOST=http://localhost:8123
54```
55
56### Step 3: Create the Client (Node.js)
57
58```typescript
59import { createClient } from '@clickhouse/client';
60
61// ClickHouse Cloud
62const client = createClient({
63 url: process.env.CLICKHOUSE_HOST, // https://<host>:8443
64 username: process.env.CLICKHOUSE_USER, // default
65 password: process.env.CLICKHOUSE_PASSWORD,
66 // ClickHouse Cloud requires TLS — the client handles it via https:// URL
67});
68
69// Self-hosted (no TLS)
70const localClient = createClient({
71 url: 'http://localhost:8123',
72 username: 'default',
73 password: '',
74});
75```
76
77### Step 4: Verify Connection
78
79```typescript
80async function verifyConnection() {
81 // Ping returns true if the server is reachable
82 const alive = await client.ping();
83 console.log('ClickHouse ping:', alive.success); // true
84
85 // Run a test query
86 const rs = await client.query({
87 query: 'SELECT version() AS ver, uptime() AS uptime_sec',
88 format: 'JSONEachRow',
89 });
90 const rows = await rs.json<{ ver: string; uptime_sec: number }>();
91 console.log('Server version:', rows[0].ver);
92 console.log('Uptime (sec):', rows[0].uptime_sec);
93}
94
95verifyConnection().catch(console.error);
96```
97
98### Step 5: Python Alternative
99
100```python
101import clickhouse_connect
102
103client = clickhouse_connect.get_client(
104 host='abc123.us-east-1.aws.clickhouse.cloud',
105 port=8443,
106 username='default',
107 password='your-password-here',
108 secure=True,
109)
110
111result = client.query('SELECT version(), uptime()')
112print(f"Version: {result.result_rows[0][0]}")
113```
114
115## Connection Options Reference
116
117| Option | Default | Description |
118|--------|---------|-------------|
119| `url` | `http://localhost:8123` | Full URL including protocol and port |
120| `username` | `default` | ClickHouse user |
121| `password` | `''` | User password |
122| `database` | `default` | Default database for queries |
123| `request_timeout` | `30000` | Query timeout in ms |
124| `compression.request` | `false` | Compress request bodies (gzip) |
125| `compression.response` | `true` | Decompress responses |
126| `max_open_connections` | `10` | HTTP keep-alive pool size |
127| `clickhouse_settings` | `{}` | Server-side settings per session |
128
129## ClickHouse Cloud vs Self-Hosted
130
131| Feature | Cloud | Self-Hosted |
132|---------|-------|-------------|
133| Port | 8443 (HTTPS) | 8123 (HTTP) / 8443 (HTTPS) |
134| TLS | Required | Optional |
135| Engine | SharedMergeTree | MergeTree family |
136| Auth | User/password, Cloud API keys | User/password, LDAP, Kerberos |
137
138## Error Handling
139
140| Error | Cause | Solution |
141|-------|-------|----------|
142| `ECONNREFUSED` | Server not running | Check host/port, verify ClickHouse is up |
143| `Authentication failed` | Wrong user/password | Verify credentials in ClickHouse users.xml or Cloud console |
144| `CERTIFICATE_VERIFY_FAILED` | TLS mismatch | Use `https://` for Cloud, check CA certs for self-hosted |
145| `TIMEOUT` | Network/firewall | Check IP allowlists in Cloud console, firewall rules |
146| `Database not found` | Wrong database name | Run `SHOW DATABASES` to list available databases |
147
148## Resources
149
150- [Official Node.js Client](https://clickhouse.com/docs/integrations/javascript)
151- [Official Python Client](https://clickhouse.com/docs/integrations/python)
152- [ClickHouse Cloud Quick Start](https://clickhouse.com/docs/cloud/get-started)
153- [HTTP Interface Reference](https://clickhouse.com/docs/interfaces/http)
154
155## Next Steps
156
157Proceed to `clickhouse-hello-world` for your first table and query.