go-sql-driver/mysql
A MySQL driver for Go database/sql supporting prepared statements, pooling, and TLS.
Official Documentation ↗v1.8. Check the official docs for the latest API surface.Installation
go get github.com/go-sql-driver/mysqlMethods
No methods match this filter.
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.
- If multiple charsets are set (separated by a comma), the following charset is used if setting the charset fails. (https://cdn.jsdelivr.net/gh/go-sql-driver/mysql@latest/README.md)
- If the check fails, the respective connection is marked as bad and the query retried with another connection. (https://cdn.jsdelivr.net/gh/go-sql-driver/mysql@latest/README.md)
- If the specified collation is unavailable on the target server, the connection will fail. (https://cdn.jsdelivr.net/gh/go-sql-driver/mysql@latest/README.md)
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.
- Sending passwords in clear text may be a security problem in some configurations. (https://cdn.jsdelivr.net/gh/go-sql-driver/mysql@latest/README.md)
- 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. (https://cdn.jsdelivr.net/gh/go-sql-driver/mysql@latest/README.md)
- These are rejected as they may introduce a SQL injection vulnerability!* ##### loc Type: string Valid Values: Default: UTC Sets the location for time.Time values (when using parseTime=true). (https://cdn.jsdelivr.net/gh/go-sql-driver/mysql@latest/README.md)
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.