CREATE DATABASE
This section describes the syntax of a CREATE DATABASE statement that is used to create a database in ClickHouse.
CREATE DATABASE Syntax
CREATE DATABASE [IF NOT EXISTS] db_name [ON CLUSTER ClickHouse cluster name];
Parameter |
Description |
---|---|
db_name |
Database name. |
IF NOT EXISTS |
You can add the IF NOT EXISTS keyword phrase to a CREATE DATABASE statement. In this case, if the name specified in the statement has been used by an existing database, no database is created and no error is returned. |
ON CLUSTER ClickHouse cluster name |
This parameter specifies the name of a cluster. |
You can run the following statement to obtain the cluster name from the cluster field:
select cluster,shard_num,replica_num,host_name from system.clusters;
Use Example
- Create a database named demo.
create database demo ON CLUSTER default_cluster;
- View the created database.
host-172-16-30-9 :) show databases; SHOW DATABASES Query id: ced1af23-0286-40cc-9c7a-ccbca41178d8 ┌─name───────────────┐ │ INFORMATION_SCHEMA │ │ default │ │ demo │ │ information_schema │ │ system │ └────────────────────┘ 5 rows in set. Elapsed: 0.002 sec.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot