explaingit

go-sql-driver/mysql

15,230GoAudience · developerComplexity · 2/5Setup · easy

TLDR

A pure-Go MySQL and MariaDB database driver that plugs into Go's standard database/sql package so any Go app can talk to MySQL with no C dependencies and no extra setup.

Mindmap

mindmap
  root((go-mysql-driver))
    What it does
      MySQL driver for Go
      Plugs into database/sql
      No CGo needed
    Connection Options
      TCP IPv4 and IPv6
      Unix socket
      Custom dial function
    Features
      Prepared statements
      Large queries
      Auto-reconnect
    Production Setup
      Connection pool config
      Timeout settings
    Audience
      Go backend developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Connect a Go web service or CLI to a MySQL or MariaDB database using the standard database/sql interface with no CGo dependencies.

USE CASE 2

Configure connection pool settings in a production Go app to prevent idle MySQL connections from being dropped by server timeouts.

USE CASE 3

Use prepared statements and large blob fields in a Go application backed by MySQL with automatic reconnection on network failures.

USE CASE 4

Connect to a MySQL database over a Unix socket in a containerized Go service for faster local communication.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min

Requires a running MySQL or MariaDB server, the driver itself installs with go get and has no C dependencies.

In plain English

Go-MySQL-Driver is a MySQL database driver for Go (also called golang). In Go, applications talk to databases through a standard interface in the language's built-in database/sql package, and this project plugs into that interface so Go programs can connect to MySQL or MariaDB servers without anything else doing the translation. It is written entirely in Go with no C bindings, which makes it lightweight to install and easy to ship as a single compiled binary. It can connect to a database over plain TCP (both IPv4 and IPv6), Unix domain sockets, or a custom dial function you provide. The driver automatically handles broken connections, supports very large queries (over 16MB), works with prepared statements and large data fields, and offers secure LOAD DATA LOCAL INFILE handling with file allowlisting. Optional features include parsing MySQL date and time values into Go's time.Time type, placeholder interpolation, and zlib compression on the wire. Once installed, a developer imports the package and opens a connection using a DSN string that follows the pattern username:password@protocol(address)/dbname?params. The README highlights connection-pool settings (SetConnMaxLifetime, SetMaxOpenConns, SetMaxIdleConns) that production apps should configure so that idle connections do not outlive the MySQL or middleware timeouts. Someone would use this whenever they are writing a Go service, CLI, or batch job that needs to read from or write to MySQL, MariaDB, or compatible servers like TiDB. It targets Go 1.24 or newer and aims to support the three most recent Go releases. The project is open source. The full README is longer than what was provided.

Copy-paste prompts

Prompt 1
Show me how to open a MySQL connection in Go using go-sql-driver with proper connection pool settings, SetMaxOpenConns, SetConnMaxLifetime, for a production API server.
Prompt 2
Write a Go function that inserts a batch of records into MySQL using prepared statements with go-sql-driver and rolls back the whole batch on any error.
Prompt 3
How do I enable time.Time parsing for MySQL date and datetime columns in go-sql-driver? Which DSN parameter do I need to add?
Prompt 4
I am getting invalid connection errors from go-sql-driver in production. What SetConnMaxLifetime value should I set to avoid MySQL wait_timeout disconnects?
Prompt 5
How do I connect go-sql-driver to a MySQL server over a Unix socket instead of TCP, and what does the DSN look like?
Open on GitHub → Explain another repo

← go-sql-driver on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.