ClickHouse:新建数据库实例

时间:2022-07-24
本文章向大家介绍ClickHouse:新建数据库实例,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1、创建数据库实例

[root@elastic1 ~]# clickhouse-client --query "CREATE DATABASE IF NOT EXISTS tutorial"
Code: 210. DB::NetException: Connection refused (localhost:9000)

[root@elastic1 ~]#

发现不能本地登录,修改配置文件

[root@elastic1 ~]# vi /etc/clickhouse-server/config.xml 
<!-- Listen specified host. use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere. -->
    <!-- <listen_host>::</listen_host> -->
    <!-- Same for hosts with disabled ipv6: -->
    <listen_host>0.0.0.0</listen_host>

    <!-- Default values - try listen localhost on ipv4 and ipv6: -->
    <listen_host>::1</listen_host>
    <!--
    <listen_host>127.0.0.1</listen_host>
    -->

修改配置文件后,重启服务

[root@elastic1 ~]# systemctl restart clickhouse-server

2、录入密码

[root@elastic1 ~]# clickhouse-client --query "CREATE DATABASE IF NOT EXISTS tutorial"
Code: 516. DB::Exception: Received from localhost:9000. DB::Exception: default: Authentication failed: password is incorrect or there is no user with such name. 

[root@elastic1 ~]#
[root@elastic1 ~]# clickhouse-client --password --query "CREATE DATABASE IF NOT EXISTS tutorial"
Password for user (default): 
[root@elastic1 ~]#

3、查看新建的数据库

[root@elastic1 ~]# clickhouse-client --password
ClickHouse client version 20.3.9.70 (official build).
Password for user (default): 
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.3.9 revision 54433.

elastic1 :) show databases;

SHOW DATABASES

┌─name─────┐
│ default  │
│ system   │
│ tutorial │
└──────────┘

3 rows in set. Elapsed: 0.003 sec. 

elastic1 :)