Go MySQL Driver implements Go’s database/sql driver interface for MySQL and MariaDB. Import the package and use the standard database/sql API with a mysql DSN.
Overview
This driver connects Go applications to MySQL-compatible servers without C bindings. It is a native Go implementation that plugs into database/sql, handling connection pooling, prepared statements, and protocol details behind the familiar Go database APIs.
Documented capabilities include automatic recovery from broken connections, large query support, LONG DATA handling in prepared statements, optional parsing of time.Time values, Unicode charset configuration, TLS and compression options including optional zstd when an extra package is imported, and controlled LOAD DATA LOCAL INFILE with allowlisting.
Configuration happens through a DSN string or Config struct, with many tunable parameters for timeouts, collation, interpolation, OIDC-related auth hooks, and connection liveness checks. The maintainers list MySQL 8.0+ and MariaDB 10.11+ as supported targets for their issue handling, and note compatibility with several third-party MySQL variants without guaranteed support.
Typical usage imports the driver anonymously, opens a sql.DB with driver name mysql, and sets recommended pool limits such as connection max lifetime and open idle counts to match server and middleware behavior.
Key features
- database/sql driver interface
- Native Go implementation
- Connection pool integration
- Prepared statement support
- TLS and compression options
- LOAD DATA LOCAL INFILE controls
- context.Context query support
- Configurable DSN parameters
Use cases
- Go apps talking to MySQL
- MariaDB backends in Go services
- sql.DB connection pooling
- Secure local INFILE imports
- Production Go microservices data layer