-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClickHouse MySQL protocol does not work with Golang MySQL driver #64071
Comments
Please provide the full reproducer (the whole Go program) and step-by-step guidance how to get this error. This will simplify the work for developers and increase chances for it to be fixed quickly. |
ch-test.zip |
The MySQL interface is mainly for specific tools that don't have native ClickHouse support yet. We also have the official ClickHouse Go driver available (clickhouse-go). In any case, if you grab the Let's Encrypt root cert, the following will work: package main
import (
"context"
"crypto/tls"
"crypto/x509"
"database/sql"
"fmt"
"log"
"os"
"github.com/go-sql-driver/mysql"
)
func main() {
ctx := context.Background()
rootCertPool := x509.NewCertPool()
pem, err := os.ReadFile("./isrgrootx1.pem")
if err != nil {
panic(err)
}
if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
log.Fatal("Failed to append PEM.")
}
err = mysql.RegisterTLSConfig("custom", &tls.Config{
ServerName: "<service>.clickhouse.cloud",
RootCAs: rootCertPool,
})
if err != nil {
panic(err)
}
db, err := sql.Open("mysql", "<username>:<password>@tcp(<service>.clickhouse.cloud:3306)/default?tls=custom")
if err != nil {
panic(err)
}
conn, _ := db.Conn(ctx)
var result string
err = conn.QueryRowContext(ctx, `SELECT version() AS result`).Scan(&result)
if err != nil {
panic(err)
}
fmt.Printf("result: %s\n", result)
} Which prints the correct result for my test instance:
Don't forget to allow the instance access for your IP address; otherwise, you might encounter the same EOF error again. |
Hi guys |
DBeaver has native ClickHouse support via the official JDBC driver — why would you use the MySQL interface for that? The same is true for DataGrip. Regarding the intended use case, our primary focus was on the (proprietary) BI tools that don't have a native plugin or driver, such as:
When possible, using native drivers is always preferred. |
I use MySQL Go driver
https://github.com/go-sql-driver/mysql
to connect to ClickHouse.Cloud using MySQL port and protocol.
I get error:
"[mysql] connection.go:49: unexpected EOF
invalid connection"
So, I am not able to connect and run any query.
The code I use is this:
cfg := mysql.Config{
User: mysql_user,
Passwd: pwd,
Net: "tcp",
Addr: host,
DBName: database,
AllowNativePasswords: true,
Params: map[string]string{"parseTime": "True"},
}
connString := cfg.FormatDSN()
conn, err := sql.Open("mysql", connString)
conn.QueryRow("select 1")
My understanding is that ClickHouse should look like MySQL for applications connecting using Go driver, that's the point of the feature, so that existing apps can be re-pointed to ClickHouse from MySQL.
The text was updated successfully, but these errors were encountered: