Friday, October 4, 2024
HomeGolangMySql connection - Getting Assist

MySql connection – Getting Assist


Attempting to hook up with mysql database on port 3306 utilizing go-sql-driver/mysql error message states [mysql] connection.go:49 sudden EOF. Any concepts why would this seem?

Hello, are you able to publish your connection code,please?
Verify this Surprising EOF in Golang Mysql Connection pool

My port 3306 is open, I also can ping the database, and log in to it utilizing the workbench.

func openDB() (*sql.DB, error) {
dsn := “person:password@tcp(10.164.27.162:3306)/database_name”
db, err := sql.Open(“mysql”, dsn)
if err != nil {
log.Deadly(err)
}
db.SetMaxOpenConns(25)
db.SetMaxIdleConns(25)
db.SetConnMaxLifetime(0)

err = db.Ping()
if err != nil {
	log.Deadly(err)
}
return db, nil

}

func (app *software) connectToDB() (*sql.DB, error) {

connection, err := openDB()
if err != nil {
	log.Deadly(err)
}
log.Println("Linked to MySQL")

return connection, nil

}
kind SqlDBRepo struct {

DB *sql.DB //pool holding database connections

}

const dbTimeout = time.Second * 3

func (m *SqlDBRepo) Connection() *sql.DB {



1 Like

In accordance the hyperlink i despatched you, setting db.SetMaxIdleConns(0) can be repair the poblem…

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments