Skip to content
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

Make protocol version check more strict #878

Merged
merged 1 commit into from
May 14, 2024

Conversation

dveeden
Copy link
Collaborator

@dveeden dveeden commented May 13, 2024

Closes #876

MySQL has:

  • Protocol version 9 (very very old on port 3306/tcp)
  • Protocol version 10 (a.k.a. Classic Protocol on port 3306/tcp)
  • Protocol version 11 (X Protocol, this is a new protocol (protobuf based) and on port 33060/tcp)

When connecting to port 33060 instead of 3306 by mistake the version check didn't return an error when it should have.

$ go run go-mysql-876.go 
2024/05/13 22:08:39 failed to query: readInitialHandshake: invalid protocol version 11, expected 10. This might be X Protocol, make sure to connect to the right port
exit status 1
package main

import (
	"database/sql"
	"log"

	_ "github.com/go-mysql-org/go-mysql/driver"
)

func main() {
	db, err := sql.Open("mysql", "root@127.0.0.1:33070")
	if err != nil {
		log.Fatalf("failed to connect to mysql: %s", err)
	}
	defer db.Close()

	_, err = db.Exec("DO 1")
	if err != nil {
		log.Fatalf("failed to query: %s", err)
	}
}
podman run -p 3307:3306 -p 33070:33060 --env MYSQL_ALLOW_EMPTY_PASSWORD=1 -it mysql:8.4.0

@lance6716 lance6716 merged commit 79f480a into go-mysql-org:master May 14, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Random connection failure in readInitialHandshake()
2 participants