API Reference

go-sql-driver/mysql

A MySQL driver for Go database/sql supporting prepared statements, pooling, and TLS.

Official Documentation ↗
CompatibilityThis documentation covers version v1.8. Check the official docs for the latest API surface.

Installation

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

Methods

The driver registers the mysql SQL dialect so database/sql can talk to MySQL or MariaDB.

Key Features

  • Connection pooling via database/sql
  • Prepared statements and parameter binding
  • TLS and timeouts through DSN options

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/go-sql-driver/mysql@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:52.537Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/go-sql-driver/mysql@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:52.537Z.

FAQ

Is sql.Open connecting immediately?
No. It only validates the DSN; the first query or a PingContext establishes a real connection.
Why do times come back as []byte?
Add parseTime=true to the DSN so DATE and DATETIME columns decode into time.Time.
How do I tune the pool?
Set SetMaxOpenConns, SetMaxIdleConns, and SetConnMaxLifetime to match your database limits and traffic.