【轻知识】3分钟,golang 操作 clickhouse
source link: https://studygolang.com/articles/28061?fr=sidebar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
安装clickhouse与使用
docker pull yandex/clickhouse-server
如果pull出现 docker pull yandex/clickhouse-server
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout
请换源。另一种方式是用dig命令然后配置hosts。这个方式有可能dig出来的ip都不好使。
docker run -d --name ck-server --ulimit nofile=262144:262144 -p 8123:8123 -p 9000:9000 -p 9009:9009 yandex/clickhouse-server
docker exec -it ck-server /bin/bash
clickhouse-client #进入数据库
建库、建表、建测试数据(均为本地测试)
create database statics engine=Ordinary;
use statics;
create table mysql_slow_log (
id UInt16,
user_name String,
host String,
sql String,
rows_examined UInt16,
exec_time UInt16,
query_time String,
create_time date
)engine=MergeTree(create_time, (id), 8192);
insert into mysql_slow_log (user_name, host, sql, rows_examined, exec_time, query_time, create_time) values('xiaoming', '127.0.0.1', 'select * from music', 3000, 1587021607, '0.333', '2020-04-16 15:32:17');
govendor fetch github.com/ClickHouse/clickhouse-go
govendor fetch github.com/jmoiron/sqlx
项目的vendor 目录用的govendor 来管理的
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: The remote end hung up unexpectedly
解决:git config http.postBuffer 524288000
代码(参考 clickhouse-go 的示例代码)
func (slowLog MysqlSlowLogModel) GetAllFromCk(offset int, pageSize int)([]MysqlSlowLogModel, error) {
connect, err := sqlx.Open("clickhouse", "tcp://127.0.0.1:9000?debug=true")
if err != nil {
return nil, errors.New("ck connect failover")
}
var items []MysqlSlowLogModel
sql := "select * from statics.mysql_slow_log";
if offset >=0 && pageSize > 0{
sql = fmt.Sprintf("%s limit %d, %d", sql, offset, pageSize)
}
if err := connect.Select(&items, sql); err != nil {
return nil, err
}
return items, nil
}
其他的操作api,在sqlx.go文件中找。readme中有示例。
参考资料:
*《DOCKER 安装clickhouse》https://www.jianshu.com/p/362252f2284b
*《大数据实时分析领域黑马开源ClickHouse》https://time.geekbang.org/column/article/40817
有疑问加站长微信联系(非本文作者)
Recommend
-
71
36氪_让一部分人先看到未来 36氪APP下载iOS & Android本站由 阿里云 提供计算与安全服务 违法和不良信息、未成年人保护举报电话:010-58254120 举报邮箱...
-
109
3分钟破100亿销售额的背后,我们把天猫双11晚会里外的黑科技都看了个遍 | 图说夜叶·2017-11-11 03:58边看着高科技,边买买买的小伙伴们,你的手还好吗?
-
130
2017双11成交3分钟破百亿 1小时超越2014年全天 2017年11月11日 00:30 25218 次阅读 稿源:
-
99
据韩国前锋报报导,昨日iPhoneX在韩国正式开放预购,但由于供货不足的原因,韩国电信商巨头SKTelecom的首批iPhoneX在3分钟内便被抢购一空。而另外一家韩国电信公司(KT)也公布了销量数据,该平台5分钟内便卖光约两万部iPhon
-
108
NIO ES8 3分钟换电功能演示 (@PS3保罗)
-
26
-
42
Spark JDBC 写 clickhouse 操作总结0.2162019.08.15 11:58:35字数 743阅读 5,773 在中小业务数据规模上通过clickhouse进行数据分析很适合,维护简单操作方便,更主要的是快;接下来...
-
10
ClickHouse Golang SQL database driver for Yandex ClickHouse Key features Uses native ClickHouse tcp client-server protocol Compatibility with database/sq...
-
5
今天的学生不了解计算机基础操作知识
-
4
知识图谱(Knowledge Graph)- Neo4j 5.10.0 使用 - Python 操作 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK