clickhouse-client(1)
Command-line client for connecting to and querying a ClickHouse database server.
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
| Flag | What it does |
|---|---|
-h, --host | ClickHouse server hostname or IP address (default: localhost) |
-p, --port | ClickHouse server port number (default: 9000 for native protocol) |
-u, --user | Username for authentication (default: default) |
--password | Password for user authentication; if omitted, prompts interactively |
-d, --database | Default database to use for queries |
-q, --query | Execute the specified query and exit (non-interactive mode) |
--format | Output format: TabSeparated, JSON, Pretty, CSV, JSONCompact, etc. |
--multiline | Allow queries to span multiple lines in interactive mode |
--vertical | Display query results in vertical format (one column per row) |
--time | Print elapsed query execution time |
--no-client-logs | Suppress client-side debug and progress logs |
Examples
Start interactive client session connected to localhost on default port
clickhouse-clientConnect to remote server with username and interactive password prompt
clickhouse-client -h 192.168.1.100 -u analyst --passwordExecute 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 PrettyExecute 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