$linuxjunkies
>

clickhouse-client(1)

Command-line client for connecting to and querying a ClickHouse database server.

UbuntuDebianFedoraArch

Synopsis

clickhouse-client [OPTION]... [--query QUERY]

Description

clickhouse-client is an interactive command-line tool for executing SQL queries against a ClickHouse OLAP database. It supports both interactive mode for manual queries and batch mode for scripted operations, with options for formatting output, authentication, and connection tuning.

The client can connect to local or remote ClickHouse servers, execute queries, and display results in various formats including TabSeparated, JSON, Pretty, and CSV. It handles large result sets efficiently and provides features like query history and auto-completion in interactive mode.

Common options

FlagWhat it does
-h, --hostClickHouse server hostname or IP address (default: localhost)
-p, --portClickHouse server port number (default: 9000 for native protocol)
-u, --userUsername for authentication (default: default)
--passwordPassword for user authentication; if omitted, prompts interactively
-d, --databaseDefault database to use for queries
-q, --queryExecute the specified query and exit (non-interactive mode)
--formatOutput format: TabSeparated, JSON, Pretty, CSV, JSONCompact, etc.
--multilineAllow queries to span multiple lines in interactive mode
--verticalDisplay query results in vertical format (one column per row)
--timePrint elapsed query execution time
--no-client-logsSuppress client-side debug and progress logs

Examples

Start interactive client session connected to localhost on default port

clickhouse-client

Connect to remote server with username and interactive password prompt

clickhouse-client -h 192.168.1.100 -u analyst --password

Execute single query and exit immediately, displaying table count

clickhouse-client -q 'SELECT count(*) FROM system.tables'

Query mydb database and return results in JSON format

clickhouse-client -d mydb --format JSON -q 'SELECT * FROM events LIMIT 10'

Pipe SQL file to client and display output in human-readable Pretty format

cat query.sql | clickhouse-client -d production --format Pretty

Execute INSERT query with execution time reporting and authentication

clickhouse-client --host click.internal -u etl_user --password --time -q 'INSERT INTO logs SELECT ...'

Display table schema in vertical format for easier reading

clickhouse-client --vertical -q 'DESCRIBE TABLE my_table'

Check ClickHouse server version with tab-separated output

clickhouse-client -q 'SELECT version()' --format TabSeparated

Related commands