Skip to content

Instantly share code, notes, and snippets.

@jessedearing
Last active August 2, 2016 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessedearing/754d020e63c1b39e2108e39b9ebf15b9 to your computer and use it in GitHub Desktop.
Save jessedearing/754d020e63c1b39e2108e39b9ebf15b9 to your computer and use it in GitHub Desktop.
Use the MySQL driver to establish connections in Golang
package main
import (
"fmt"
"log"
"database/sql/driver"
"github.com/go-sql-driver/mysql"
)
const CONNECTIONS int = 100
func main() {
fmt.Printf("Creating %d connections\n", CONNECTIONS)
var conns []driver.Conn
for i := 0; i < CONNECTIONS; i++ {
conns = append(conns, mysqlConn())
}
var a *string
fmt.Scanf("%f\n", &a)
}
func mysqlConn() driver.Conn {
driv := &mysql.MySQLDriver{}
conn, err := driv.Open("user:password@tcp(127.0.0.1:3306)/mydb")
if err != nil {
log.Fatal(err)
}
return conn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment