Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:37:32+00:00 2026-06-07T04:37:32+00:00

I am looking for a reliable solution to connect to a MySQL database from

  • 0

I am looking for a reliable solution to connect to a MySQL database from Go. I’ve seen some libraries around, but it is difficult to determine the different states of completeness and current maintenance. I don’t have complex needs, but I’d like to know what people are relying on or the most standard solution to connect to MySQL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:37:33+00:00Added an answer on June 7, 2026 at 4:37 am

    A few drivers are available but you should only consider those that implement the database/sql API as

    • it provides a clean and efficient syntax,
    • it ensures you can later change the driver without changing your code, apart the import and connection.

    Two fast and reliable drivers are available for MySQL :

    • MyMySQL
    • Go-MySQL-Driver

    I’ve used both of them in production, programs are running for months with connection numbers in the millions without failure.

    Other SQL database drivers are listed on go-wiki.

    Import when using MyMySQL :

    import (
        "database/sql"
        _ "github.com/ziutek/mymysql/godrv"
    )
    

    Import when using Go-MySQL-Driver :

    import (
        "database/sql"
        _ "github.com/go-sql-driver/mysql"
    )
    

    Connecting and closing using MyMySQL :

    con, err := sql.Open("mymysql", database+"/"+user+"/"+password)
    defer con.Close()
    // here you can use the connection, it will be closed when function returns
    

    Connecting and closing using Go-MySQL-Driver :

    con, err := sql.Open("mysql", store.user+":"+store.password+"@/"+store.database)
    defer con.Close()
    

    Select one row :

    row := con.QueryRow("select mdpr, x, y, z from sometable where id=?", id)
    cb := new(SomeThing)
    err := row.Scan(&cb.Mdpr, &cb.X, &cb.Y, &cb.Z)
    

    Select multiple rows and build an array with results :

    rows, err := con.Query("select a, b from item where p1=? and p2=?", p1, p2)
    if err != nil { /* error handling */}
    items := make([]*SomeStruct, 0, 10)
    var ida, idb uint
    for rows.Next() {
        err = rows.Scan(&ida, &idb)
        if err != nil { /* error handling */}
        items = append(items, &SomeStruct{ida, idb})
    }
    

    Insert :

    _, err = con.Exec("insert into tbl (id, mdpr, isok) values (?, ?, 1)", id, mdpr)
    

    You’ll see that working in Go with MySQL is a delightful experience : I never had a problem, my servers run for months without errors or leaks. The fact that most functions simply take a variable number of arguments lighten a task which is tedious in many languages.

    Note that if, in the future, you need to use another MySQL driver, you’ll just have to change two lines in one go file : the line doing the import and the line opening the connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a good quality and reliable mapping solution for South Africa.
I am looking for a lightweight, reliable and fast key/value database for storing binary
I am looking for an affordable and reliable VPS solution serving Windows Server 2008.
I'm looking for a reliable mocking framework for ActionScript. I've been using mock-as3, but
I am looking for some suggestions or possibly a solution I've overlooked for an
I'm playing with waitpid() and signal() and I'm looking for reliable test cases for
I am looking for a reliable method to replace a sequence of chars in
I am looking for a reliable P2P framework or library, preferrably natively written in
I was looking for a reliable, clean way to do advanced runtime reports for
I'm looking for a reliable mechanism to generate a server side postback handler for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.