go连接ClickHouse, 响应 driver: bad connection,通过客户端能连上,不知是否与驱动版本有关

采用官方最简单的例子,始终不行, 希望有经验的大佬帮忙看下,感谢
go.mod

module ck-test

go 1.16

require (
    github.com/ClickHouse/clickhouse-go v1.4.1
    github.com/jmoiron/sqlx v1.2.1-0.20200614204820-f5f08a7e27f6
)

main.go

package main

import (
    _ "github.com/ClickHouse/clickhouse-go"
    "github.com/jmoiron/sqlx"
)


func main()  {
    connect, err := sqlx.Open("clickhouse", "tcp://127.0.0.1:9000?debug=true&read_timeout=10&write_timeout=10")
    if err != nil {
        panic(err)
    }
    var items []interface{}

    sql := "select * from statics.mysql_slow_log";

    if err := connect.Select(&items, sql); err != nil {
        panic(err)
    }

}

异常:

[clickhouse]host(s)=127.0.0.1:9000, database=default, username=default
[clickhouse][dial] secure=false, skip_verify=false, strategy=random, ident=1, server=0 -> 127.0.0.1:9000
[clickhouse][connect=1][hello] -> Golang SQLDriver 1.1.54213
[clickhouse][connect=1][connect] read error: read tcp 127.0.0.1:49634->127.0.0.1:9000: i/o timeout
[clickhouse]host(s)=127.0.0.1:9000, database=default, username=default
[clickhouse][dial] secure=false, skip_verify=false, strategy=random, ident=2, server=0 -> 127.0.0.1:9000
[clickhouse][connect=2][hello] -> Golang SQLDriver 1.1.54213
[clickhouse][connect=2][connect] read error: read tcp 127.0.0.1:49638->127.0.0.1:9000: i/o timeout
[clickhouse]host(s)=127.0.0.1:9000, database=default, username=default
[clickhouse][dial] secure=false, skip_verify=false, strategy=random, ident=3, server=0 -> 127.0.0.1:9000
[clickhouse][connect=3][hello] -> Golang SQLDriver 1.1.54213
[clickhouse][connect=3][connect] read error: read tcp 127.0.0.1:49641->127.0.0.1:9000: i/o timeout
panic: driver: bad connection
阅读 7k
2 个回答

database=default, username=default ?

你不填具体的库名,也没有用户名,密码?

新手上路,请多包涵

本地的9000端口是否正常,下个客户端连一下8123看下,服务是否正常启动

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题