2020-04-27 20:45

系统要求
如果从官方仓库安装,需要确保您使用的是x86_64处理器构架的Linux并且支持SSE 4.2指令集
 
检查是否支持SSE 4.2:
 
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
 

#使用脚本安装yum源
curl -s https://packagecloud.io/install/repositories/altinity/clickhouse/script.rpm.sh | sudo bash
#yum 安装 server 以及 client
sudo yum install -y clickhouse-server clickhouse-client
#查看是否安装完成
sudo yum list installed 'clickhouse*'
#开机启动clickhouse-server 
systemctl enable clickhouse-server
#启动clickhouse-client
systemctl start clickhouse-client 

 
# 启动server端clickhouse-server
service clickhouse-server start
 
# 查看server端服务开启/关闭状态 
service clickhouse-server status
 
# 进入client端clickhouse-client

clickhouse-client

clickhouse-client -h 127.0.0.1


=====================

卸载:
 
# 卸载及删除安装文件(需root权限)
yum list installed | grep clickhouse
 
yum remove -y clickhouse-common-static
 
yum remove -y clickhouse-server-common
 
rm -rf /var/lib/clickhouse
 
rm -rf /etc/clickhouse-*
 
rm -rf /var/log/clickhouse-server

卸载报错时强制删除:
 
# 删除rpm包的时候不调用卸载脚本
sudo rpm -e clickhouse-server.x86_64 --noscripts


创建表:
CREATE TABLE demo.domains (id UInt16,name String,dns String,ip String,countryip String,countryhtml String,webservertype String,hostname String,emails String,alex String,phone String,majestic String,create_date date) ENGINE = MergeTree(create_date, (id), 8192);

cat /opt/sample_1852.csv | clickhouse-client -h 127.0.0.1 --query="INSERT INTO demo.domains FORMAT CSV"


导入的CSV文件没有字段名称时:
 
cat csv文件路径 | clickhouse-client --query="INSERT INTO 数据库.表名 FORMAT CSV"
 
导入的CSV文件有字段名称时
 
cat csv文件路径 | clickhouse-client --query="INSERT INTO 数据库.表名 FORMAT CSVWithNames"