ClickHouse Ubuntu Terminal Remote Client

How to install the ClickHouse Ubuntu command line client and connect to your Altinity.Cloud cluster.

26 January 2023 · Read time 2 min

Overview - Ubuntu ClickHouse Client

This section covers the installation of the ClickHouse client on the Linux OS Ubuntu 20.04.
After installation, you will be able to run use ClickHouse queries from the terminal.

Updating Ubuntu

  1. Update your Ubuntu OS and confirm the version with the following commands:

    sudo apt-get update
    sudo apt-get upgrade
    lsb_release -a
    

Installing ClickHouse drivers

To install ClickHouse drivers on Ubuntu 20.04:

  1. Copy and paste each of the following lines to your Ubuntu terminal in sequence:

    sudo apt-get install -y apt-transport-https ca-certificates dirmngr
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
    echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list
    sudo apt-get update
    sudo apt-get install -y clickhouse-client
    clickhouse-client --version
       ClickHouse client version 22.12.3.5 (official build).
    

More information

Logging on to your cluster

  1. From the Connection Details, copy and paste the text string to your Ubuntu terminal:

     clickhouse-client -h example-cluster.your-domain.altinity.cloud --port 9440 -s --user=admin --password
    

ClickHouse terminal response

  1. After you enter your ClickHouse cluster password, you enter the ClickHouse interactive mode.
    ClickHouse prompt example: example-cluster :)

    (test2) user@xubuntu:~$ clickhouse-client -h example-cluster.your-domain.altinity.cloud --port 9440 -s --user=admin --password
    ClickHouse client version 22.12.3.5 (official build).
    Password for user (admin): 
    *********
    
    Connecting to example-cluster.your-domain.altinity.cloud:9440 as user admin.
    Connected to ClickHouse server version 22.3.15 revision 54455.
    
    ClickHouse server version is older than ClickHouse client. 
    It may indicate that the server is out of date and can be upgraded.
    
    example-cluster :) 
    

ClickHouse query examples

  1. At the ClickHouse prompt, enter the query command show tables:

    example-cluster :) show tables
    
    SHOW TABLES
    
    Query id: c319298f-2f28-48fe-96ca-ce59aacdbc43
    
    ┌─name─────────┐
    │ events       │
    │ events_local │
    └──────────────┘
    
    2 rows in set. Elapsed: 0.080 sec.
    
  2. At the ClickHouse prompt, enter the query select * from events:

    example-cluster :) select * from events
    
    SELECT *
    FROM events
    
    Query id: 0e4d08b3-a52d-4a03-917d-226c6a2b00ac
    
    ┌─event_date─┬─event_type─┬─article_id─┬─title───┐
    │ 2023-01-04 │          113 │ Example │
    │ 2023-01-10 │          113 │ Example │
    │ 2023-01-10 │          114 │ Example │
    └────────────┴────────────┴────────────┴─────────┘
    
    3 rows in set. Elapsed: 0.073 sec.
    

To quit, or exit from the ClickHouse interactive mode:

  1. Enter the exit command to return to your Ubuntu shell environment.

    example-cluster :) exit
    Bye.
    

This completes the quick start guide to installing ClickHouse command-line client on an Ubuntu OS.

Related links

Troubleshooting

Make sure you have the latest ClickHouse client installed to avoid connection issues.

Problem

  • Error Code: 210 SSL connection unexpectedly closed.
  • Problem result: Cannot connect to ACM Cluster with clickhouse-client terminal command.
ubuntu@ip-172-31-16-238:~$ clickhouse-client -h test-anywhere.awsanywhere.altinity.cloud --port 9440 -s --user=admin --password=supersecretpassword123

# Error response: note the older version of the ClickHouse client v18.16.1
ClickHouse client version 18.16.1.
Connecting to test-anywhere.awsanywhere.altinity.cloud:9440 as user admin.
Code: 210. DB::NetException: SSL connection unexpectedly closed (test-gap-anyw.awsanywhere.altinity.cloud:9440, 33.33.33.333)

Reason for the error

When you have an outdated version of the ClickHouse client software installed, you may fail to connect to your ACM cluster. The issue may be that a standard apt-get install or apt-get upgrade will not retrieve the latest version of the ClickHouse client as shown in this example terminal listing.

sudo apt install clickhouse-client
...
# Note the older client
Get:25 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 clickhouse-common amd64 18.16.1+ds-7 [9266 kB]
Get:26 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 clickhouse-client amd64 18.16.1+ds-7 [138 kB]
---

Solution
The solution is to follow the instructions on this page:

Last modified 0001.01.01