Last active
August 2, 2016 22:19
-
-
Save jessedearing/754d020e63c1b39e2108e39b9ebf15b9 to your computer and use it in GitHub Desktop.
Use the MySQL driver to establish connections in Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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