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