1 ClickHouse安装

  1. 安装文件清单
clickhouse-client-${version}.noarch.rpm
clickhouse-common-static-dbg-${version}.x86_64.rpm
clickhouse-common-static-${version}.x86_64.rpm
clickhouse-server-${version}.noarch.rpm

clickhouse的安装只需要上面4个文件

  1. 安装命令
命令1: rpm -ivh *.rpm
命令2: yum install *.rpm
  1. 卸载
    查看
rpm -qa | grep clickhouse

卸载命令:

rpm -e  rpm包名

如果卸载不了,使用:

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

卸载报错时强制删除:

# 删除rpm包的时候不调用卸载脚本
sudo rpm -e clickhouse-server.x86_64 --noscripts
  1. 启动/关闭服务
systemctl start clickhouse-server
systemctl status clickhouse-server
systemctl restart clickhouse-server
  1. 交互式命令
clickhouse-client
select 1
  1. 测试数据
    下载下面文件,使用wget方式下载
wget https://clickhouse-datasets.s3.yandex.net/hits/tsv/hits_v1.tsv.xz
wget https://clickhouse-datasets.s3.yandex.net/visits/tsv/visits_v1.tsv.xzyum install xz xz -d hits_v1.tsv.xz
xz -d visits_v1.tsv.xz
  1. 创建数据库
clickhouse-client --query "CREATE DATABASE IF NOT EXISTS tutorial"
  1. 建表
    创建hits_v1表
clickhouse-client  -m
CREATE TABLE tutorial.hits_v1
(`WatchID` UInt64,`JavaEnable` UInt8,`Title` String,`GoodEvent` Int16,`EventTime` DateTime,`EventDate` Date,`CounterID` UInt32,`ClientIP` UInt32,`ClientIP6` FixedString(16),`RegionID` UInt32,`UserID` UInt64,`CounterClass` Int8,`OS` UInt8,`UserAgent` UInt8,`URL` String,`Referer` String,`URLDomain` String,`RefererDomain` String,`Refresh` UInt8,`IsRobot` UInt8,`RefererCategories` Array(UInt16),`URLCategories` Array(UInt16),`URLRegions` Array(UInt32),`RefererRegions` Array(UInt32),`ResolutionWidth` UInt16,`ResolutionHeight` UInt16,`ResolutionDepth` UInt8,`FlashMajor` UInt8,`FlashMinor` UInt8,`FlashMinor2` String,`NetMajor` UInt8,`NetMinor` UInt8,`UserAgentMajor` UInt16,`UserAgentMinor` FixedString(2),`CookieEnable` UInt8,`JavascriptEnable` UInt8,`IsMobile` UInt8,`MobilePhone` UInt8,`MobilePhoneModel` String,`Params` String,`IPNetworkID` UInt32,`TraficSourceID` Int8,`SearchEngineID` UInt16,`SearchPhrase` String,`AdvEngineID` UInt8,`IsArtifical` UInt8,`WindowClientWidth` UInt16,`WindowClientHeight` UInt16,`ClientTimeZone` Int16,`ClientEventTime` DateTime,`SilverlightVersion1` UInt8,`SilverlightVersion2` UInt8,`SilverlightVersion3` UInt32,`SilverlightVersion4` UInt16,`PageCharset` String,`CodeVersion` UInt32,`IsLink` UInt8,`IsDownload` UInt8,`IsNotBounce` UInt8,`FUniqID` UInt64,`HID` UInt32,`IsOldCounter` UInt8,`IsEvent` UInt8,`IsParameter` UInt8,`DontCountHits` UInt8,`WithHash` UInt8,`HitColor` FixedString(1),`UTCEventTime` DateTime,`Age` UInt8,`Sex` UInt8,`Income` UInt8,`Interests` UInt16,`Robotness` UInt8,`GeneralInterests` Array(UInt16),`RemoteIP` UInt32,`RemoteIP6` FixedString(16),`WindowName` Int32,`OpenerName` Int32,`HistoryLength` Int16,`BrowserLanguage` FixedString(2),`BrowserCountry` FixedString(2),`SocialNetwork` String,`SocialAction` String,`HTTPError` UInt16,`SendTiming` Int32,`DNSTiming` Int32,`ConnectTiming` Int32,`ResponseStartTiming` Int32,`ResponseEndTiming` Int32,`FetchTiming` Int32,`RedirectTiming` Int32,`DOMInteractiveTiming` Int32,`DOMContentLoadedTiming` Int32,`DOMCompleteTiming` Int32,`LoadEventStartTiming` Int32,`LoadEventEndTiming` Int32,`NSToDOMContentLoadedTiming` Int32,`FirstPaintTiming` Int32,`RedirectCount` Int8,`SocialSourceNetworkID` UInt8,`SocialSourcePage` String,`ParamPrice` Int64,`ParamOrderID` String,`ParamCurrency` FixedString(3),`ParamCurrencyID` UInt16,`GoalsReached` Array(UInt32),`OpenstatServiceName` String,`OpenstatCampaignID` String,`OpenstatAdID` String,`OpenstatSourceID` String,`UTMSource` String,`UTMMedium` String,`UTMCampaign` String,`UTMContent` String,`UTMTerm` String,`FromTag` String,`HasGCLID` UInt8,`RefererHash` UInt64,`URLHash` UInt64,`CLID` UInt32,`YCLID` UInt64,`ShareService` String,`ShareURL` String,`ShareTitle` String,`ParsedParams` Nested(Key1 String,Key2 String,Key3 String,Key4 String,Key5 String,ValueDouble Float64),`IslandID` FixedString(16),`RequestNum` UInt32,`RequestTry` UInt8
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(EventDate)
ORDER BY (CounterID, EventDate, intHash32(UserID))
SAMPLE BY intHash32(UserID)
SETTINGS index_granularity = 8192;
CREATE TABLE tutorial.visits_v1
(`CounterID` UInt32,`StartDate` Date,`Sign` Int8,`IsNew` UInt8,`VisitID` UInt64,`UserID` UInt64,`StartTime` DateTime,`Duration` UInt32,`UTCStartTime` DateTime,`PageViews` Int32,`Hits` Int32,`IsBounce` UInt8,`Referer` String,`StartURL` String,`RefererDomain` String,`StartURLDomain` String,`EndURL` String,`LinkURL` String,`IsDownload` UInt8,`TraficSourceID` Int8,`SearchEngineID` UInt16,`SearchPhrase` String,`AdvEngineID` UInt8,`PlaceID` Int32,`RefererCategories` Array(UInt16),`URLCategories` Array(UInt16),`URLRegions` Array(UInt32),`RefererRegions` Array(UInt32),`IsYandex` UInt8,`GoalReachesDepth` Int32,`GoalReachesURL` Int32,`GoalReachesAny` Int32,`SocialSourceNetworkID` UInt8,`SocialSourcePage` String,`MobilePhoneModel` String,`ClientEventTime` DateTime,`RegionID` UInt32,`ClientIP` UInt32,`ClientIP6` FixedString(16),`RemoteIP` UInt32,`RemoteIP6` FixedString(16),`IPNetworkID` UInt32,`SilverlightVersion3` UInt32,`CodeVersion` UInt32,`ResolutionWidth` UInt16,`ResolutionHeight` UInt16,`UserAgentMajor` UInt16,`UserAgentMinor` UInt16,`WindowClientWidth` UInt16,`WindowClientHeight` UInt16,`SilverlightVersion2` UInt8,`SilverlightVersion4` UInt16,`FlashVersion3` UInt16,`FlashVersion4` UInt16,`ClientTimeZone` Int16,`OS` UInt8,`UserAgent` UInt8,`ResolutionDepth` UInt8,`FlashMajor` UInt8,`FlashMinor` UInt8,`NetMajor` UInt8,`NetMinor` UInt8,`MobilePhone` UInt8,`SilverlightVersion1` UInt8,`Age` UInt8,`Sex` UInt8,`Income` UInt8,`JavaEnable` UInt8,`CookieEnable` UInt8,`JavascriptEnable` UInt8,`IsMobile` UInt8,`BrowserLanguage` UInt16,`BrowserCountry` UInt16,`Interests` UInt16,`Robotness` UInt8,`GeneralInterests` Array(UInt16),`Params` Array(String),`Goals` Nested(ID UInt32,Serial UInt32,EventTime DateTime,Price Int64,OrderID String,CurrencyID UInt32),`WatchIDs` Array(UInt64),`ParamSumPrice` Int64,`ParamCurrency` FixedString(3),`ParamCurrencyID` UInt16,`ClickLogID` UInt64,`ClickEventID` Int32,`ClickGoodEvent` Int32,`ClickEventTime` DateTime,`ClickPriorityID` Int32,`ClickPhraseID` Int32,`ClickPageID` Int32,`ClickPlaceID` Int32,`ClickTypeID` Int32,`ClickResourceID` Int32,`ClickCost` UInt32,`ClickClientIP` UInt32,`ClickDomainID` UInt32,`ClickURL` String,`ClickAttempt` UInt8,`ClickOrderID` UInt32,`ClickBannerID` UInt32,`ClickMarketCategoryID` UInt32,`ClickMarketPP` UInt32,`ClickMarketCategoryName` String,`ClickMarketPPName` String,`ClickAWAPSCampaignName` String,`ClickPageName` String,`ClickTargetType` UInt16,`ClickTargetPhraseID` UInt64,`ClickContextType` UInt8,`ClickSelectType` Int8,`ClickOptions` String,`ClickGroupBannerID` Int32,`OpenstatServiceName` String,`OpenstatCampaignID` String,`OpenstatAdID` String,`OpenstatSourceID` String,`UTMSource` String,`UTMMedium` String,`UTMCampaign` String,`UTMContent` String,`UTMTerm` String,`FromTag` String,`HasGCLID` UInt8,`FirstVisit` DateTime,`PredLastVisit` Date,`LastVisit` Date,`TotalVisits` UInt32,`TraficSource` Nested(ID Int8,SearchEngineID UInt16,AdvEngineID UInt8,PlaceID UInt16,SocialSourceNetworkID UInt8,Domain String,SearchPhrase String,SocialSourcePage String),`Attendance` FixedString(16),`CLID` UInt32,`YCLID` UInt64,`NormalizedRefererHash` UInt64,`SearchPhraseHash` UInt64,`RefererDomainHash` UInt64,`NormalizedStartURLHash` UInt64,`StartURLDomainHash` UInt64,`NormalizedEndURLHash` UInt64,`TopLevelDomain` UInt64,`URLScheme` UInt64,`OpenstatServiceNameHash` UInt64,`OpenstatCampaignIDHash` UInt64,`OpenstatAdIDHash` UInt64,`OpenstatSourceIDHash` UInt64,`UTMSourceHash` UInt64,`UTMMediumHash` UInt64,`UTMCampaignHash` UInt64,`UTMContentHash` UInt64,`UTMTermHash` UInt64,`FromHash` UInt64,`WebVisorEnabled` UInt8,`WebVisorActivity` UInt32,`ParsedParams` Nested(Key1 String,Key2 String,Key3 String,Key4 String,Key5 String,ValueDouble Float64),`Market` Nested(Type UInt8,GoalID UInt32,OrderID String,OrderPrice Int64,PP UInt32,DirectPlaceID UInt32,DirectOrderID UInt32,DirectBannerID UInt32,GoodID String,GoodName String,GoodQuantity Int32,GoodPrice Int64),`IslandID` FixedString(16)
)
ENGINE = CollapsingMergeTree(Sign)
PARTITION BY toYYYYMM(StartDate)
ORDER BY (CounterID, StartDate, intHash32(UserID), VisitID)
SAMPLE BY intHash32(UserID)
SETTINGS index_granularity = 8192
  1. 数据导入
    –max_insert_block_size=100000:表示每次批量导入100000行。
date
clickhouse-client --query "INSERT INTO tutorial.hits_v1 FORMAT TSV" --max_insert_block_size=100000 < hits_v1.tsv
dateclickhouse-client --query "INSERT INTO tutorial.visits_v1 FORMAT TSV" --max_insert_block_size=100000 < visits_v1.tsv

查询一下数据(如果想按照好的格式显示,可以在最后加上WG):
select * from hits_v1 limit 1; \G

  1. 查询
SELECTStartURL AS URL,AVG(Duration) AS AvgDuration
FROM tutorial.visits_v1
WHERE StartDate BETWEEN '2014-03-23' AND '2014-03-30'
GROUP BY URL
ORDER BY AvgDuration DESC
LIMIT 10;SELECTsum(Sign) AS visits,sumIf(Sign, has(Goals.ID, 1105530)) AS goal_visits,(100. * goal_visits) / visits AS goal_percent
FROM tutorial.visits_v1
WHERE (CounterID = 912887) AND (toYYYYMM(StartDate) = 201403) AND (domain(StartURL) = 'yandex.ru');

2 clickhouse-client

交互式模式:clickhouse-client
非交互式模式: 指定了–query参数或将数据发送至标准的stdin。

测试表创建:

create database if not exists test;
use test;
drop table test;
create table test(id UInt8, text String, created DateTime) ENGINE=TinyLog;

批模式数据导入:

echo -ne "1, 'some text', '2016-08-14 00:00:00'\n2, 'some more text', '2016-08-14 00:00:01'" | clickhouse-client --database=test --query="INSERT INTO test FORMAT CSV";cat <<_EOF | clickhouse-client --database=test --query="INSERT INTO test FORMAT CSV";
3, 'some text', '2016-08-14 00:00:00'
4, 'some more text', '2016-08-14 00:00:01'
_EOFselect * from test.test;\G

总结:
(1)、批模式下的默认数据格式为TabSeparated,可使用FORMAT指定格式。
(2)、使用–multiquery参数,可同时执行多个查询(除了INSERT),每个查询语句使用分号(;)分隔。
(3)、使用–multiline或-m参数,允许执行多行的查询。
(4)、在查询语句的分号之后指定\G或使用\G替换分号, 数据以垂直的格式展示。
(5)、历史的执行语句保存在操作系统文件:~/.clickhouse-client-history。
(6)、退出客户端的方式,按Ctrl + D或Ctrl + C,或执行命令:exit、quit、logout、q、Q、:q。

查询中指定参数:

clickhouse-client --param_myid=3 --database=test --query="select * from test where id>{myid:UInt8}"
clickhouse-client --database=test --query="select * from test where id>3"

查询语句指定参数,参数值通过客户端参数传递。
使用大括号占位要传递的参数值,格式为: {:}
name:占位标识符。通过clickhouse-client参数指定,格式为–param_ = value 。
data type:指定参数值的数据类型,例如:UInt8、String等。

clickhouse-client --param_parName="[1, 2]"  -q "SELECT * FROM table WHERE a = {parName:Array(UInt16)}"clickhouse-client --query="select * from test.test FORMAT TabSeparated" > file.tsv

clickhouse-client查找配置文件的顺序:
(1)、通过–config-file指定的配置文件。
(2)、./clickhouse-client.xml
(3)、~/.clickhouse-client/config.xml
(4)、/etc/clickhouse-client/config.xml

{host}
{port}
{user}
{database}
{display_name}

3 MySQL接口操作ClickHouse

  1. 安装MySQL的客户端
tar -xzf MySQL-client-5.6.38-1.el6.x86_64.tar.gz
rpm -ivh MySQL-client-5.6.38-1.el6.x86_64.rpm
  1. 配置MySQL协议
vim /etc/clickhouse-server/config.xml
<mysql_port>9004</mysql_port>

重启clickhouse

systemctl restart clickhouse-server

命令行连接到ClickHouse:

mysql --protocol tcp -u default -P 9004

为了兼容所有MySQL客户端,建议使用SHA1加密用户密码(即修改访问密码,下面的命令直接在服务器上执行):

PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD"  \
| sha1sum | tr -d '-' | xxd -r -p | sha1sum | tr -d '-'
0FeOfptD                                    这个作为用户名
e6f07fa4a54a8d81a3fd318378311d8fd5ae8e6c    密码

修改配置文件:vim /etc/clickhouse-server/users.xml

将<password></password>注释,然后添加如下:
<password_double_sha1_hex>e6f07fa4a54a8d81a3fd318378311d8fd5ae8e6c</password_double_sha1_hex>

执行命令:

mysql --protocol tcp -u default -P 9004 --password=0FeOfptD

4 DBeaver可视化工具安装与使用

  1. 安装DBeaver (软件下载地址:https://dbeaver.io/download/ ;安装方式是直接下一步下一步的方式进行安装:)
  2. 下载DBeaver的JDBC驱动
  3. 连接ClickHouse, 注意,配置CH的网络
/etc/clickhouse-server/config.xml
<listen_host>0.0.0.0</listen_host>
  1. 使用DBeaver连接ClickHouse



    编辑如下内容:

    点击"编辑驱动设置"



    添加阿里云的源

    URL:http://maven.aliyun.com/nexus/content/groups/public/
    然后点击"应用",“Apply and Close”,一直点击到最后。

在"SQL编辑器”里,可以点击"SQL编辑器"。在编辑器中可以编写sql语句。

  1. 设置参数
    在URL模板中,设置ClickHouse的参数
jdbc:clickhouse://{host}:{port}[/{database}]?socket_timeout=600000&max_bytes_before_external_group_by=20000000

配置参数:

timeout
socket_timeout

外部聚合,如果用于聚合内存不足,10G

max_bytes_before_external_group_by=5G

02_clickhouse安装,卸载,启动/关闭服务,交互式命令(数据库创建,数据导入,查询),批模式数据导入,MySQL接口操作ClickHouse,DBeaver可视化工具安装与使用(学习笔记)相关推荐

  1. 【02】Java进阶:18-MySQL基础、数据库概述、数据库的安装/卸载/启动/登录、SQL概述、DDL操作数据库、DDL操作表、DML增删改查、

    day18-MySql基础 今日内容 数据库概述 数据库安装和卸载 SQL语句 DDL-----操作数据库,操作表 DML-----操作记录(增删改) DQL------操作记录(查) 学习目标 能够 ...

  2. 在linux操作系统中启动oracle数据库程序,Linux系统下Oracle数据库的安装和启动关闭操作教程...

    这篇文章主要介绍了Linux系统下Oracle数据库的安装和启动关闭操作教程,并针对在sqlplus下所需执行的命令进行讲解,需要的朋友可以参考下 1.准备: df -H 查看空间剩余   一般准备最 ...

  3. linux启动postfix命令,如何在Linux停止和启动postfix服务的命令

    1.启动Postfix服务 启动Postfix服务的命令为:/etc/init.d/postfix start 命令执行后如图所示,则表示启动Postfix服务成功. 2.停止Postfix服务 停止 ...

  4. linux启动网络服务的命令,linux重启服务命令

    linux重启服务命令 重启:service 服务名 restart 或systemctl restart 服务名 service和systemctl 1.service命令 service命令其实是 ...

  5. mysql 启动慢_MySQL启动关闭服务巨慢,这样解决!

    墨墨导读:正常情况下 MySQL 关闭启动服务的为什么会很慢?大家遇到过这种情况吗?作者将解决的详细过程分享至此,希望可以帮助到读者朋友. 有一次,在客户现场,调优的时候发现配置128G内存服务器,但 ...

  6. 2017-06-13共享时出现错误,没有启动服务器服务,此时尚未创建共享资源”的解决办法

    1.原因windows xp 不能共享 处理了 computer brower+server 都正常,只是windows 防火墙不能启动 后来使用了windowsrepair解决了些问题!在些给大家提 ...

  7. Redis介绍及可视化工具安装详解及redis基础指令(小白++)

    1.Redis介绍及安装 1.1Redis介绍 Redis(Remote Dictionary Server),即远程字典服务,是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日 ...

  8. Ubuntu14.04下Mongodb数据库可视化工具安装部署步骤(图文详解)(博主推荐)

    不多说,直接上干货! 前期博客 Ubuntu14.04下Mongodb(离线安装方式|非apt-get)安装部署步骤(图文详解)(博主推荐) Ubuntu14.04下Mongodb官网安装部署步骤(图 ...

  9. 批处理启动vm虚拟机服务 vm12启动无界面启动vm虚拟机系统 windows上如何操作服务 sc net启动关闭服务...

    windows(win10)批处理脚本 打开vm虚拟机的服务,并且开启无界面虚拟机 @echo off net start "vds" net start "VMAuth ...

最新文章

  1. Java Excel 插入图片
  2. 马斯克的第七个孩子曝光:终于有女儿了!前女友所“生”,名字非常赛博朋克...
  3. C# 修改项目文件夹名称完全版
  4. 微信小程序的页面渲染(if/for)
  5. QOMO Linux 4.0 正式版发布
  6. 面向切面编程--AOP
  7. python读csv最快方法_使用Python读写csv文件的三种方法
  8. flask框架(四):通过局域网访问网站
  9. 【剑指 offer】(十三)—— 在 O(1) 时间删除链表结点
  10. ajax获取checkbox循环出来的值_Django:前后端异步加载数据(循环大法)
  11. 如何解决更改csdn头像修改后浏览器不显示的问题
  12. 微信小程序系列(5)如何用微信小程序写一个论坛?贴心代码详解(三)列表页
  13. 【Python成长之路】卡萨帝冰箱能买吗?让数据来说话!
  14. 圆梦天宫,英雄凯旋—从神州十三号看IP技术在航天测控通信网的应用
  15. HTML期末学生大作业 响应式动漫网页作业 html+css+javascript (1)
  16. 商品规格常用的规格排列组合算法
  17. Web GIS多种方式发布动态地图服务及显示(2)
  18. Python自动化运维开发实战
  19. 拯救者R9000p搜不到wifi 解决方法
  20. SaaS爆发前夜,e签宝的选择与命运

热门文章

  1. SpringMVC实现文件的上传与下载
  2. MyBatis运行原理(一)SqlSessionFactory对象创建过程分析
  3. VTK:柏拉图式固体用法实战
  4. wxWidgets:wxPaintEvent类用法
  5. boost::units模块实现异构单元片段
  6. boost::strict_lock相关的测试程序
  7. boost::push_back相关的测试程序
  8. 使用 Boost.MPI 的 reduce() 连接字符串的示例
  9. GDCM:将DICOM文件和XML文件相互转换的测试程序
  10. VTK:PolyData之ContourToImageData