clickhouse快速入门(入门篇必看必会)

1.  启动clickhouse-client

clickhouse-client --user xx --password xx

2. 再外部连接clickhouse客户端 并导出表中数据到本地 

# 连接clickhouse客户端并导出db库中的test表 带表头的导出到指令目录下
##  >> 是追加,  > 是覆盖
cickhouse-client --password -d <指定数据库> \
-q"select * from db.test format CSVWithNames" \
--format_csv_delimiter=, --input_format_allow_errors_num=1 \
--input_format_allow_errors_ratio=0.1
>> /opt/test.csv 


其中--input_format_allow_errors_ratio=0.1 表示允许有百分之10的错误率
    --input_format_allow_errors_num=1 这个表示允许有不匹配的数据一条

3. 如果clickhouse的密码忘记 :查找path:

cat /etc/clickhouse-server/users.xml

4. clickhouse对于schema的定义是很严格的严格再类型必须大小写分明

eg : UInt8、UInt16、String、DateTime, TimeStamp 但是比函数名不敏感:SUM()-> sum()

与mysql中不同哦 

5. 建表语句 存储引擎: MergeTree

库: db , 表 : fo
create table db.fo (
`id` UInt64, 
`name` String,
`otdtime` TimeStamp,
`dateOpt` DateTime)ENGINE=MergeTree    存储引擎
primary key 'id'   # id 是唯一的
order by  id
Settings index_granularity=8129  # 设置索引级别 每个数据块包含8129行,8129为一个默认数
# MergeTree引擎仅读取查询所需要的列,减少i/o , 以为其建表时指定了primary 和orderby 
# 所以是有序的 , 且分段, MergeTree会按照顺序进行有序的存储新的数据

6. 建表 存储引擎 : Log 没有约束

create table fo(id UInt64 , name String)
ENGINE=Log 
# 使用与小规模的快速插入,无需长期保存的数据

7. 修改表名

rename table db.fo to db.fffo   # 原表名fo , 新表名fffo

8. 写入数据:

clickhouse-client --password xx -d db -p"inset into test values(2,"foo",43)"

9. 写入csv文件并忽略表头字段

clickhouse-client --password xx -d db -q"insert into test format CSV" \
--format_csv_delimiter=, \
--input_format_allow_errors_num=1 < /opt/tex.csv

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值