mysql is a free, open source databases project written in Go and released under MPL-2.0. It has 15,284 GitHub stars, 2,334 forks and 57 open issues, and was last pushed 13 hours ago. On this registry it ranks #50 of 143 tracked projects in Databases, with 5 head-to-head comparisons available.

What is mysql?

Go-MySQL-Driver is the pure-Go MySQL driver that implements the database/sql interface for Go applications, and it is aimed at Go developers who need to connect services to MySQL, MariaDB, or TiDB without cgo or C bindings.

What it is

Go-MySQL-Driver, published as github.com/go-sql-driver/mysql, is a database driver for Go's standard database/sql package. It implements the driver side of that interface, so application code keeps using sql.Open, sql.DB, and the usual query and transaction methods while the package handles the wire protocol, authentication, and connection lifecycle. It is written entirely in Go, with no C bindings and no external client library to link against.

It lives in the Go ecosystem and replaces a CGO-based binding to libmysqlclient. That matters for cross compilation, static binaries, and container images, because a program can be built for another platform without a MySQL client library installed on the build machine. The package also covers the parts that are easy to get wrong by hand: broken connections, connection pooling through database/sql, queries larger than the usual packet ceiling, and DSN parsing that turns one connection string into protocol, address, credentials, and parameters.

Key capabilities

  • Native Go implementation with no C bindings, so builds do not need libmysqlclient.
  • Connections over TCP/IPv4, TCP/IPv6, Unix domain sockets, or custom protocols through a DialFunc.
  • Automatic handling of broken connections, plus automatic connection pooling provided by database/sql.
  • Support for queries larger than 16MB and full sql.RawBytes support.
  • Intelligent LONG DATA handling in prepared statements.
  • Secure LOAD DATA LOCAL INFILE support with file allowlisting and io.Reader input.
  • Optional time.Time parsing, optional placeholder interpolation, zlib compression, and support for Unicode.

Who uses it and how

  • Backend services and APIs written in Go that hold a long-lived sql.DB pool and rely on database/sql for pooling, timeouts, and context.Context cancellation.
  • Containerised workloads that reach a MySQL or MariaDB node over a Unix domain socket or TCP/IPv6, where a pure-Go static binary removes the need to ship client libraries in the image.
  • Data import jobs that use LOAD DATA LOCAL INFILE with an allowlist and an io.Reader instead of shelling out to the mysql command-line client.
  • Teams running TiDB, which PingCAP supports for this driver, though the README routes TiDB questions to PingCAP documentation and its forum rather than the project issue tracker.
  • Applications that need streaming access to column data through sql.RawBytes or precise time.Time handling for DATETIME and TIMESTAMP columns.

Getting started

Install the package from a shell with go get -u github.com/go-sql-driver/mysql, then open a handle through database/sql with a DSN carrying the protocol, address, credentials, and parameters. Go 1.25 or higher is required.

How it compares

The facts provided do not name any alternative driver or paid product that this project replaces, so it stands alone in this registry.

When to use it — and when not to

Choose it when the application is written in Go, targets MySQL 8.0 or later or MariaDB 10.11 or later, and benefits from a pure-Go build that cross-compiles without client libraries. Do not choose it if you need an ORM, a query builder, migrations, or a database administration interface, because this is a driver only and those concerns sit in other packages. Note the support boundary as well: Percona Server, Google CloudSQL, and Sphinx may work, but maintainers state they will not investigate issues for them and expect a pull request instead, and the Go 1.25 minimum rules out older toolchains.

project readme (upstream, from github) — read inline

Go-MySQL-Driver

DeepWiki

A MySQL-Driver for Go's database/sql package

Go-MySQL-Driver logo



Features

  • Lightweight and fast
  • Native Go implementation. No C-bindings, just pure Go
  • Connections over TCP/IPv4, TCP/IPv6, Unix domain sockets or custom protocols
  • Automatic handling of broken connections
  • Automatic Connection Pooling (by database/sql package)
  • Supports queries larger than 16MB
  • Full sql.RawBytes support.
  • Intelligent LONG DATA handling in prepared statements
  • Secure LOAD DATA LOCAL INFILE support with file allowlisting and io.Reader support
  • Optional time.Time parsing
  • Optional placeholder interpolation
  • Supports zlib compression.

Requirements

  • Go 1.25 or higher. We aim to support the 3 latest versions of Go.
  • MySQL (8.0+) and MariaDB (10.11+) are supported by maintainers.
  • TiDB is supported by PingCAP.
    • Do not ask questions about TiDB in our issue tracker or forum.
    • Document
    • Forum
  • go-mysql would work with Percona Server, Google CloudSQL or Sphinx (2.2.3+).
    • Maintainers won't support them. Do not expect issues are investigated and resolved by maintainers.
    • Investigate issues yourself and please send a pull request to fix it.

Installation

Simple install the package to your $GOPATH with the go tool from shell:

go get -u github.com/go-sql-driver/mysql

Make sure Git is installed on your machine and in your system's PATH.

Usage

Go MySQL Driver is an implementation of Go's database/sql/driver interface. You only need to import the driver and can use the full database/sql API then.

Use mysql as driverName and a valid DSN as dataSourceName:

import (
	"database/sql"
	"time"

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

// ...

db, err := sql.Open("mysql", "user:password@/dbname")
if err != nil {
	panic(err)
}
// See "Important settings" section.
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)

Examples are available in our Wiki.

Important settings

db.SetConnMaxLifetime() is required to ensure connections are closed by the driver safely before connection is closed by MySQL server, OS, or other middlewares. Since some middlewares close idle connections by 5 minutes, we recommend timeout shorter than 5 minutes. This setting helps load balancing and changing system variables too.

db.SetMaxOpenConns() is highly recommended to limit the number of connection used by the application. There is no recommended limit number because it depends on application and MySQL server.

db.SetMaxIdleConns() is recommended to be set same to db.SetMaxOpenConns(). When it is smaller than SetMaxOpenConns(), connections can be opened and closed much more frequently than you expect. Idle connections can be closed by the db.SetConnMaxLifetime(). If you want to close idle connections more rapidly, you can use db.SetConnMaxIdleTime() since Go 1.15.

DSN (Data Source Name)

The Data Source Name has a common format, like e.g. PEAR DB uses it, but without type-prefix (optional parts marked by squared brackets):

[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]

A DSN in its fullest form:

username:password@protocol(address)/dbname?param=value

Except for the databasename, all values are optional. So the minimal DSN is:

/dbname

If you do not want to preselect a database, leave dbname empty:

/

This has the same effect as an empty DSN string:

dbname is escaped by PathEscape() since v1.8.0. If your database name is dbname/withslash, it becomes:

/dbname%2Fwithslash

Alternatively, Config.FormatDSN can be used to create a DSN string by filling a struct.

Password

Passwords can consist of any character. Escaping is not necessary.

Protocol

See net.Dial for more information which networks are available. In general you should use a Unix domain socket if available and TCP otherwise for best performance.

Address

For TCP and UDP networks, addresses have the form host[:port]. If port is omitted, the default port will be used. If host is a literal IPv6 address, it must be enclosed in square brackets. The functions net.JoinHostPort and net.SplitHostPort manipulate addresses in this form.

For Unix domain sockets the address is the absolute path to the MySQL-Server-socket, e.g. /var/run/mysqld/mysqld.sock or /tmp/mysql.sock.

Parameters

Parameters are case-sensitive!

Notice that any of true, TRUE, True or 1 is accepted to stand for a true boolean value. Not surprisingly, false can be specified as any of: false, FALSE, False or 0.

allowAllFiles
Type:           bool
Valid Values:   true, false
Default:        false

allowAllFiles=true disables the file allowlist for LOAD DATA LOCAL INFILE and allows all files. Might be insecure!

allowCleartextPasswords
Type:           bool
Valid Values:   true, false
Default:        false

allowCleartextPasswords=true allows using the cleartext client side plugin if required by an account, such as one defined with the PAM authentication plugin. Sending passwords in clear text may be a security problem in some configurations. To avoid problems if there is any possibility that the password would be intercepted, clients should connect to MySQL Server using a method that protects the password. Possibilities include TLS / SSL, IPsec, or a private network

readme truncated — read the full docs on github

Frequently asked questions

Is mysql free to use?

mysql is open source under the MPL-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does mysql do?

Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package

What is mysql written in?

mysql is primarily written in Go. Its source is publicly available at https://github.com/go-sql-driver/mysql, and it has 15,284 GitHub stars.