I\'m using the github.com/go-sql-driver/mysql driver for go.
I open a database:
db, err := sql.Open(\"mysql\", str)
Then I have two fun
The *DB
object that you get back from sql.Open
doesn't corresponds to a single connection. It is better thought as a handle for the database: it manages a connection pool for you.
You can control the number of open connections with `(*DB).SetMaxOpenConns and its pair for idling connections.
So basically what happens here is that db.Query
and db.QueryRow
tries to acquire a connection for themselves and the DB handle doesn't put any restrictions on the number of simultaneous connections so your code panics when it opens more than what mysql can handle.