Answer the question
In order to leave comments, you need to log in
golang server not responding with frequent db requests?
There is a function for working with the database
db := mysql.New("tcp", "", "127.0.0.1:3306", "root", "", "test")
err := db.Connect()
if err != nil {
log.Println("Не удалось подключиться к базе данных")
}
rows, _, err := db.Query(Query,args...)
if err != nil {
log.Println("Не удалось выполнить запрос",Query,err)
}
return rows
Answer the question
In order to leave comments, you need to log in
You are connecting to the database on every request, that's really bad.
Connect to the database once when the application starts, and when processing a request, use a ready-made connection.
Try
db.SetMaxIdleConns(n int)
db.SetMaxOpenConns(n int)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question