Updated on 2024-04-29 GMT+08:00

Using Clickhouse Commands

This section describes common ClickHouse commands. After installing the ClickHouse client and loading environment variables, run the following commands to perform operations:

  1. Connect to the ClickHouse cluster.
    Use the following command to connect to a normal cluster.
    ./clickhouse client --host Private IP address of the cluster   --port Port --user admin --password Password

    For details about the security cluster connection command. For details, see Connecting to a Security Cluster.

    ./clickhouse client --host Private IP address of the cluster --port port --user admin --password Password --secure --config-file /root/config.xml
  2. Create a database.
    create database demo;
  3. Use the database.
    use demo;
  4. Check the database in use.
    select currentDatabase();
  5. Create a table.
    create table demo_t(uid Int32,name String,age UInt32,gender String)engine = TinyLog;
  6. View the table structure.
    desc demo_t;
  7. Insert data.
    insert into demo_t values(1,'Candy','23','M'),(2,'cici','33','F');
  8. View the table.
    select * from demo_t;
  9. View the database and table.
    • Viewing the database
      show databases;
    • Viewing the table
      show tables;
  10. Delete the database and table.
    • Deleting the table
      drop table demo_t;
      • Before deleting a data table, check whether the data table is in use to avoid unnecessary troubles.
      • After a data table is deleted, it can be restored within 24 hours. The restoration command is as follows:
        set allow_experimental_undrop_table_query = 1;
        UNDROP TABLE Data table name;
    • Deleting the database
      drop database demo;