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:
- 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 9000 --user admin --password PasswordFor details about the security cluster connection command. For details, see Using the ClickHouse Client to Connect to a Cluster.
./clickhouse client --host Private IP address of the cluster --port 9440 --user admin --password Password --secure --config-file /root/config.xml - Create a database.create database demo;
- Use the database.use demo;
- Check the database in use.select currentDatabase();
- Create a table.create table demo_t(uid Int32,name String,age UInt32,gender String)engine = TinyLog;
- View the table structure.desc demo_t;
- Insert data.insert into demo_t values(1,'Candy','23','M'),(2,'cici','33','F');
- View the table.select * from demo_t;
- View the database and table.
- Viewing the databaseshow databases;
- Viewing the tableshow tables;
- Viewing the database
- Delete the database and table.
- Deleting the tabledrop table demo_t;Note
- 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 databasedrop database demo;
- Deleting the table
Parent topic: Connecting to a ClickHouse Cluster