mysql: MySQL 5.7 Aborted Connection - Got an error reading communication packets

Issue description

The connection to MySQL should open. However, opening this connection in Golang, results in the error (Got an error reading communication packets). Opening the MySQL connection from the cli works.

Tried:

  • Increasing the wait_time
  • Increasing the connection_time
  • Increasing the max packet size

Example code

func open_mysql(Host *string, Username *string, Password *string, Database *string, parameters string) *sql.DB {
	open, err := sql.Open("mysql", *Username+":"+*Password+"@tcp("+*Host+")/"+*Database+parameters)

	if err != nil {
		log.Printf("%s\n", err)
	}
	return open
}

Error log

[Note] Aborted connection 13086 to db: '<redacted>' user: '<redacted>' host: '<redacted but not localhost, outside network connection>' (Got an error reading communication packets)

Configuration

Driver version (or git SHA): latest pull from go get -u github.com/go-sql-driver/mysql as of today.

Go version: go version go1.7.5 darwin/amd64 AND go version go1.8 darwin/amd64

Server version: Server version: 5.7.17-0ubuntu0.16.04.1 (Ubuntu)

Server OS: Ubuntu 16.04.1

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 15
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I know this is old issue, but when I search this problem, this issue appear in search result In my case, the problem appear because I forgot to close connection.

so just don’t forget to close your connection db.Close()

I solve this issue by commenting on the values of wait_timeout, interactive_timeout, connect_timeout on my mysql.sock. My warning message is stopped after commenting this lines. By default, wait_time and interactive_timeout will be 28800, when installing MySQL 5.7 in my production server, MySQL added this lines, after commenting this 3 lines it worked without showing a warning message: " [Note] Aborted connection to db: ‘-----’ user: ‘----’ host: ‘localhost’ (Got timeout reading communication packets)"

I’m not sure if it was the OS upgrade (macOS 10.13) or the MariaDB upgrade (10.2.9-MariaDB Homebrew), but I can reproduce this bug now.

The cause seems to be our beloved strict mode. If I disable it, everything works fine.