Trying to connect to mysql database on port 3306 using go-sql-driver/mysql error message states [mysql] connection.go:49 unexpected EOF. Any ideas why would this appear?
Hi, can you publish your connection code,please?
Check this Unexpected EOF in Golang Mysql Connection pool
My port 3306 is open, I can also ping the database, and log in to it using the workbench.
func openDB() (*sql.DB, error) {
dsn := “user:password@tcp(10.164.27.162:3306)/database_name”
db, err := sql.Open(“mysql”, dsn)
if err != nil {
log.Fatal(err)
}
db.SetMaxOpenConns(25)
db.SetMaxIdleConns(25)
db.SetConnMaxLifetime(0)
err = db.Ping()
if err != nil {
log.Fatal(err)
}
return db, nil
}
func (app *application) connectToDB() (*sql.DB, error) {
connection, err := openDB()
if err != nil {
log.Fatal(err)
}
log.Println("Connected to MySQL")
return connection, nil
}
type SqlDBRepo struct {
DB *sql.DB //pool holding database connections
}
const dbTimeout = time.Second * 3
func (m *SqlDBRepo) Connection() *sql.DB {
According the link i sent you, setting db.SetMaxIdleConns(0) would be fix the poblem…
maybe db.SetConnMaxLifetime(0)
is wrong,delete this