Skip to content

With compress=true, cannot query DB after calling Ping #1718

Closed
@evanelias

Description

@evanelias

Issue description

When connecting to a database using compress=true, any use of DB.Ping() seems to cause subsequent queries to not return rows.

Ping itself does not return an error.

Example code

package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	db, err := sql.Open("mysql", "root:mypw@tcp(127.0.0.1:3306)/?compress=1")
	if err != nil {
		panic(err)
	}
	defer db.Close()
	if err = db.Ping(); err != nil {
		panic("Ping error: " + err.Error())
	}
	var version string
	query := "SELECT @@global.version"
	err = db.QueryRow(query).Scan(&version)
	if err != nil {
		panic("QueryRow error: " + err.Error())
	}
	fmt.Println(version)
}

Error log

panic: QueryRow error: sql: no rows in result set

If I replace the call to QueryRow with Query and a loop over rows, the loop does not execute (there are no rows, even though selecting a global variable should always result in 1 row).

If I change compress=1 to compress=0, the code works properly and prints the server version.

Alternatively, if I comment-out the Ping call, the code works properly.

Configuration

Driver version (or git SHA): 1.9.2

Go version: go version go1.24.4 darwin/arm64

Server version: Tested with both MySQL 8.0.40 and MariaDB 11.4.5, same behavior with both

Server OS: Linux (VM via Docker Desktop for Mac) - MySQL was on Oracle Linux, MariaDB was on Debian

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions