Skip to content

Instantly share code, notes, and snippets.

@ammario
Last active October 15, 2016 19:12
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 ammario/d6964966f73853a490de77b9d5b8daa0 to your computer and use it in GitHub Desktop.
Save ammario/d6964966f73853a490de77b9d5b8daa0 to your computer and use it in GitHub Desktop.
Golang connect to MySQL
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
mysqlConn, err := sql.Open("mysql", os.Getenv("MYSQL_USER")+":"+os.Getenv("MYSQL_PASS")+"@("+os.Getenv("MYSQL_HOST")+")/"+os.Getenv("MYSQL_DB") + "?parseTime=true")
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment