-
ClickHouse
ClickHouse 是俄罗斯的 Yandex 于 2016 年开源的列式存储数据库(DBMS),主要用于在线分析处理查询(OLAP),能够使用 SQL 查询实时生成分析数据报告。
-
1安装依赖
[root@hadoop102 ~]# yum install -y libtool
[root@hadoop102 ~]# yum install -y *unixODBC*
2.下载
官网:
https://clickhouse.yandex/
下载地址:http://repo.red-soft.biz/repos/clickhouse/stable/el6/
3.上传、安装
1 [root@hadoop102 software]# ls 2 clickhouse-client-1.1.54236-4.el6.x86_64.rpm 3 clickhouse-server-1.1.54236-4.el6.x86_64.rpm 4 clickhouse-compressor-1.1.54236-4.el6.x86_64.rpm 5 clickhouse-server-common-1.1.54236-4.el6.x86_64.rpm 6 clickhouse-debuginfo-1.1.54236-4.el6.x86_64.rpm
1 [root@hadoop102 software]# rpm -ivh *.rpm Preparing... ########################################### [100%] 2 1:clickhouse-server- commo########################################### [ 20%] 3 2:clickhouse-server ########################################### [ 40%] 4 3:clickhouse-client 5 大数据技术之 Clickhouse ########################################### [ 60%] 6 4:clickhouse-debuginfo ########################################### [ 80%] 7 5:clickhouse-compressor ########################################### [100%]
4.后台启动
1 [root@hadoop102 software]# nohup clickhouse-server --config- file=/etc/clickhouse-server/config.xml >null 2>&1 &
注:
>null --重定向输出
2>&1 --重定向绑定;详见另一篇:https://www.cnblogs.com/zhipeng-wang/p/14123777.html
5.启动客户端
[root@hadoop102 software]# clickhouse-client
ClickHouse client version 1.1.54236.
Connecting to localhost:9000.
Connected to ClickHouse server version 1.1.54236.
:)
6.数据类型
整形,浮点型,布尔,字符串,枚举,数组,元组,日期
7.引擎类型--engine
TinyLog,Memory,Merge,MergeTree,ReplacingMergeTre,UmmingMergeTree,Distribuated
8.创建表--create
基本语法:CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster] ( name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1], name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2], ... ) ENGINE = engine 直接创建: :) create table t1(id UInt16,name String) engine=TinyLog 复制表结构创建: :) create table t2 as t1 engine=Memory 复制指定表的指定列创建: :) create table t3 engine=TinyLog as select * from t1
9.插入表数据 --insert
直接插入: :) insert into t1 values(1,'zhangsan'),(2,'lisi'),(3,'wangwu') 插入指定表中的指定数据: :) insert into t2 select * from t3
10.修改表 --alter
ALTER 只支持 MergeTree 系列,Merge 和 Distributed 引擎的表,基本语法:
ALTER TABLE [db].name [ON CLUSTER cluster] ADD|DROP|MODIFY
COLUMN ...
参数解析:
ADD COLUMN – 向表中添加新列
DROP COLUMN – 在表中删除列
MODIFY COLUMN – 更改列的类型
添加指定列
:)alter table mt_table add column age UInt8
修改指定列
:)alter table mt_table modify column age UInt16
删除指定列
:)alter table mt_table drop column age
11.查看表结构--describe
:)desc mt_table
12.检查表--check table
检查表中的数据是否损坏,他会返回两种结果:
0 – 数据已损坏
1 – 数据完整
该命令只支持 Log,TinyLog 和 StripeLog 引擎。