Skip to content

Instantly share code, notes, and snippets.

@bliaxiong
Created December 31, 2014 06:25
Show Gist options
  • Save bliaxiong/562a36d9bda596002efa to your computer and use it in GitHub Desktop.
Save bliaxiong/562a36d9bda596002efa to your computer and use it in GitHub Desktop.
Go mysql sqlx example
package main
import (
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"log"
)
type User struct {
Id int
First, Last, Email string
}
func main() {
db, err := sqlx.Connect("mysql", "test:test@(localhost:3306)/test")
if err != nil {
log.Fatalln(err)
}
user := []User{}
db.Select(&user, "select * from users")
log.Println("users...")
log.Println(user)
}
@cholthi
Copy link

cholthi commented Dec 2, 2019

Thank you for posting this. Useful

@bliaxiong
Copy link
Author

I stopped using Go a long time ago and had to google how to create a connection, I found my own Gist. LOL.

@chetan-giradkar
Copy link

I stopped using Go a long time ago and had to google how to create a connection, I found my own Gist. LOL.

Can you please explain the 2nd argument of db, err := sqlx.Connect("mysql", "test:test@(localhost:3306)/test")

@bliaxiong
Copy link
Author

bliaxiong commented May 24, 2021 via email

@ihsanbudiman
Copy link

I stopped using Go a long time ago and had to google how to create a connection, I found my own Gist. LOL.

huh... what?? hahahahaha

@odil5
Copy link

odil5 commented Apr 24, 2024

thanks for useful information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment