Skip to content

Instantly share code, notes, and snippets.

@bliaxiong
Created December 31, 2014 06:25
Show Gist options
  • Select an option

  • Save bliaxiong/562a36d9bda596002efa to your computer and use it in GitHub Desktop.

Select an option

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)
}
@GitSumito
Copy link
Copy Markdown

Thank you. This information was really helpful.

@cholthi
Copy link
Copy Markdown

cholthi commented Dec 2, 2019

Thank you for posting this. Useful

@bliaxiong
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Author

bliaxiong commented May 24, 2021 via email

@ihsanbudiman
Copy link
Copy Markdown

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
Copy Markdown

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