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-auth3description: |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:*), Grep10version: 1.0.011license: MIT12author: Jeremy Longshore <jeremy@intentsolutions.io>13tags: [saas, database, analytics, clickhouse, olap]14compatible-with: claude-code15---1617# ClickHouse Install & Auth1819## Overview2021Set up the official ClickHouse client for Node.js or Python and configure authentication22to ClickHouse Cloud or a self-hosted instance.2324## Prerequisites2526- Node.js 18+ or Python 3.8+27- A running ClickHouse instance (Cloud or self-hosted)28- Connection credentials (host, port, user, password)2930## Instructions3132### Step 1: Install the Official Client3334```bash35# Node.js — official client (HTTP-based, supports streaming)36npm install @clickhouse/client3738# Python — official client39pip install clickhouse-connect40```4142### Step 2: Configure Environment Variables4344```bash45# .env (NEVER commit — add to .gitignore)46CLICKHOUSE_HOST=https://abc123.us-east-1.aws.clickhouse.cloud:844347CLICKHOUSE_USER=default48CLICKHOUSE_PASSWORD=your-password-here4950# Self-hosted (HTTP interface on port 8123, native on 9000)51# CLICKHOUSE_HOST=http://localhost:812352```5354### Step 3: Create the Client (Node.js)5556```typescript57import { createClient } from '@clickhouse/client';5859// ClickHouse Cloud60const client = createClient({61 url: process.env.CLICKHOUSE_HOST, // https://<host>:844362 username: process.env.CLICKHOUSE_USER, // default63 password: process.env.CLICKHOUSE_PASSWORD,64 // ClickHouse Cloud requires TLS — the client handles it via https:// URL65});6667// Self-hosted (no TLS)68const localClient = createClient({69 url: 'http://localhost:8123',70 username: 'default',71 password: '',72});73```7475### Step 4: Verify Connection7677```typescript78async function verifyConnection() {79 // Ping returns true if the server is reachable80 const alive = await client.ping();81 console.log('ClickHouse ping:', alive.success); // true8283 // Run a test query84 const rs = await client.query({85 query: 'SELECT version() AS ver, uptime() AS uptime_sec',86 format: 'JSONEachRow',87 });88 const rows = await rs.json<{ ver: string; uptime_sec: number }>();89 console.log('Server version:', rows[0].ver);90 console.log('Uptime (sec):', rows[0].uptime_sec);91}9293verifyConnection().catch(console.error);94```9596### Step 5: Python Alternative9798```python99import clickhouse_connect100101client = clickhouse_connect.get_client(102 host='abc123.us-east-1.aws.clickhouse.cloud',103 port=8443,104 username='default',105 password='your-password-here',106 secure=True,107)108109result = client.query('SELECT version(), uptime()')110print(f"Version: {result.result_rows[0][0]}")111```112113## Connection Options Reference114115| Option | Default | Description |116|--------|---------|-------------|117| `url` | `http://localhost:8123` | Full URL including protocol and port |118| `username` | `default` | ClickHouse user |119| `password` | `''` | User password |120| `database` | `default` | Default database for queries |121| `request_timeout` | `30000` | Query timeout in ms |122| `compression.request` | `false` | Compress request bodies (gzip) |123| `compression.response` | `true` | Decompress responses |124| `max_open_connections` | `10` | HTTP keep-alive pool size |125| `clickhouse_settings` | `{}` | Server-side settings per session |126127## ClickHouse Cloud vs Self-Hosted128129| Feature | Cloud | Self-Hosted |130|---------|-------|-------------|131| Port | 8443 (HTTPS) | 8123 (HTTP) / 8443 (HTTPS) |132| TLS | Required | Optional |133| Engine | SharedMergeTree | MergeTree family |134| Auth | User/password, Cloud API keys | User/password, LDAP, Kerberos |135136## Error Handling137138| Error | Cause | Solution |139|-------|-------|----------|140| `ECONNREFUSED` | Server not running | Check host/port, verify ClickHouse is up |141| `Authentication failed` | Wrong user/password | Verify credentials in ClickHouse users.xml or Cloud console |142| `CERTIFICATE_VERIFY_FAILED` | TLS mismatch | Use `https://` for Cloud, check CA certs for self-hosted |143| `TIMEOUT` | Network/firewall | Check IP allowlists in Cloud console, firewall rules |144| `Database not found` | Wrong database name | Run `SHOW DATABASES` to list available databases |145146## Resources147148- [Official Node.js Client](https://clickhouse.com/docs/integrations/javascript)149- [Official Python Client](https://clickhouse.com/docs/integrations/python)150- [ClickHouse Cloud Quick Start](https://clickhouse.com/docs/cloud/get-started)151- [HTTP Interface Reference](https://clickhouse.com/docs/interfaces/http)152153## Next Steps154155Proceed to `clickhouse-hello-world` for your first table and query.156