{"id":13366068,"url":"https://github.com/Go-sql-driver/mysql","last_synced_at":"2025-03-12T17:32:08.698Z","repository":{"id":5866072,"uuid":"7083242","full_name":"go-sql-driver/mysql","owner":"go-sql-driver","description":"Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package","archived":false,"fork":false,"pushed_at":"2024-08-30T05:38:05.000Z","size":1449,"stargazers_count":14503,"open_issues_count":71,"forks_count":2310,"subscribers_count":408,"default_branch":"master","last_synced_at":"2024-10-23T16:11:38.602Z","etag":null,"topics":["database","go","mariadb","mysql","mysql-driver","sql"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/go-sql-driver/mysql","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-sql-driver.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-12-09T20:33:55.000Z","updated_at":"2024-10-23T15:32:07.000Z","dependencies_parsed_at":"2023-02-16T17:40:29.227Z","dependency_job_id":"a8bbed56-6cff-4969-8b2d-3734de718dd5","html_url":"https://github.com/go-sql-driver/mysql","commit_stats":{"total_commits":782,"total_committers":162,"mean_commits":4.827160493827161,"dds":0.6445012787723785,"last_synced_commit":"00dc21a6243c02c1a84fc82d08a821c08fde4053"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-sql-driver%2Fmysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-sql-driver%2Fmysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-sql-driver%2Fmysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-sql-driver%2Fmysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-sql-driver","download_url":"https://codeload.github.com/go-sql-driver/mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221305503,"owners_count":16795146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","go","mariadb","mysql","mysql-driver","sql"],"created_at":"2024-07-30T00:01:18.640Z","updated_at":"2025-03-12T17:32:08.682Z","avatar_url":"https://github.com/go-sql-driver.png","language":"Go","readme":"# Go-MySQL-Driver\n\nA MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) package\n\n![Go-MySQL-Driver logo](https://raw.github.com/wiki/go-sql-driver/mysql/gomysql_m.png \"Golang Gopher holding the MySQL Dolphin\")\n\n---------------------------------------\n  * [Features](#features)\n  * [Requirements](#requirements)\n  * [Installation](#installation)\n  * [Usage](#usage)\n    * [DSN (Data Source Name)](#dsn-data-source-name)\n      * [Password](#password)\n      * [Protocol](#protocol)\n      * [Address](#address)\n      * [Parameters](#parameters)\n      * [Examples](#examples)\n    * [Connection pool and timeouts](#connection-pool-and-timeouts)\n    * [context.Context Support](#contextcontext-support)\n    * [ColumnType Support](#columntype-support)\n    * [LOAD DATA LOCAL INFILE support](#load-data-local-infile-support)\n    * [time.Time support](#timetime-support)\n    * [Unicode support](#unicode-support)\n  * [Testing / Development](#testing--development)\n  * [License](#license)\n\n---------------------------------------\n\n## Features\n  * Lightweight and [fast](https://github.com/go-sql-driver/sql-benchmark \"golang MySQL-Driver performance\")\n  * Native Go implementation. No C-bindings, just pure Go\n  * Connections over TCP/IPv4, TCP/IPv6, Unix domain sockets or [custom protocols](https://godoc.org/github.com/go-sql-driver/mysql#DialFunc)\n  * Automatic handling of broken connections\n  * Automatic Connection Pooling *(by database/sql package)*\n  * Supports queries larger than 16MB\n  * Full [`sql.RawBytes`](https://golang.org/pkg/database/sql/#RawBytes) support.\n  * Intelligent `LONG DATA` handling in prepared statements\n  * Secure `LOAD DATA LOCAL INFILE` support with file allowlisting and `io.Reader` support\n  * Optional `time.Time` parsing\n  * Optional placeholder interpolation\n  * Supports zlib compression.\n\n## Requirements\n\n* Go 1.21 or higher. We aim to support the 3 latest versions of Go.\n* MySQL (5.7+) and MariaDB (10.5+) are supported.\n* [TiDB](https://github.com/pingcap/tidb) is supported by PingCAP.\n  * Do not ask questions about TiDB in our issue tracker or forum.\n  * [Document](https://docs.pingcap.com/tidb/v6.1/dev-guide-sample-application-golang)\n  * [Forum](https://ask.pingcap.com/)\n* go-mysql would work with Percona Server, Google CloudSQL or Sphinx (2.2.3+).\n  * Maintainers won't support them. Do not expect issues are investigated and resolved by maintainers.\n  * Investigate issues yourself and please send a pull request to fix it.\n\n---------------------------------------\n\n## Installation\nSimple install the package to your [$GOPATH](https://github.com/golang/go/wiki/GOPATH \"GOPATH\") with the [go tool](https://golang.org/cmd/go/ \"go command\") from shell:\n```bash\ngo get -u github.com/go-sql-driver/mysql\n```\nMake sure [Git is installed](https://git-scm.com/downloads) on your machine and in your system's `PATH`.\n\n## Usage\n_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`](https://golang.org/pkg/database/sql/) API then.\n\nUse `mysql` as `driverName` and a valid [DSN](#dsn-data-source-name)  as `dataSourceName`:\n\n```go\nimport (\n\t\"database/sql\"\n\t\"time\"\n\n\t_ \"github.com/go-sql-driver/mysql\"\n)\n\n// ...\n\ndb, err := sql.Open(\"mysql\", \"user:password@/dbname\")\nif err != nil {\n\tpanic(err)\n}\n// See \"Important settings\" section.\ndb.SetConnMaxLifetime(time.Minute * 3)\ndb.SetMaxOpenConns(10)\ndb.SetMaxIdleConns(10)\n```\n\n[Examples are available in our Wiki](https://github.com/go-sql-driver/mysql/wiki/Examples \"Go-MySQL-Driver Examples\").\n\n### Important settings\n\n`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.\n\n`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.\n\n`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.\n\n\n### DSN (Data Source Name)\n\nThe Data Source Name has a common format, like e.g. [PEAR DB](http://pear.php.net/manual/en/package.database.db.intro-dsn.php) uses it, but without type-prefix (optional parts marked by squared brackets):\n```\n[username[:password]@][protocol[(address)]]/dbname[?param1=value1\u0026...\u0026paramN=valueN]\n```\n\nA DSN in its fullest form:\n```\nusername:password@protocol(address)/dbname?param=value\n```\n\nExcept for the databasename, all values are optional. So the minimal DSN is:\n```\n/dbname\n```\n\nIf you do not want to preselect a database, leave `dbname` empty:\n```\n/\n```\nThis has the same effect as an empty DSN string:\n```\n\n```\n\n`dbname` is escaped by [PathEscape()](https://pkg.go.dev/net/url#PathEscape) since v1.8.0. If your database name is `dbname/withslash`, it becomes:\n\n```\n/dbname%2Fwithslash\n```\n\nAlternatively, [Config.FormatDSN](https://godoc.org/github.com/go-sql-driver/mysql#Config.FormatDSN) can be used to create a DSN string by filling a struct.\n\n#### Password\nPasswords can consist of any character. Escaping is **not** necessary.\n\n#### Protocol\nSee [net.Dial](https://golang.org/pkg/net/#Dial) for more information which networks are available.\nIn general you should use a Unix domain socket if available and TCP otherwise for best performance.\n\n#### Address\nFor TCP and UDP networks, addresses have the form `host[:port]`.\nIf `port` is omitted, the default port will be used.\nIf `host` is a literal IPv6 address, it must be enclosed in square brackets.\nThe functions [net.JoinHostPort](https://golang.org/pkg/net/#JoinHostPort) and [net.SplitHostPort](https://golang.org/pkg/net/#SplitHostPort) manipulate addresses in this form.\n\nFor 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`.\n\n#### Parameters\n*Parameters are case-sensitive!*\n\nNotice 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`.\n\n##### `allowAllFiles`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\n`allowAllFiles=true` disables the file allowlist for `LOAD DATA LOCAL INFILE` and allows *all* files.\n[*Might be insecure!*](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-local)\n\n##### `allowCleartextPasswords`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\n`allowCleartextPasswords=true` allows using the [cleartext client side plugin](https://dev.mysql.com/doc/en/cleartext-pluggable-authentication.html) if required by an account, such as one defined with the [PAM authentication plugin](http://dev.mysql.com/doc/en/pam-authentication-plugin.html). 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](#tls), IPsec, or a private network.\n\n\n##### `allowFallbackToPlaintext`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\n`allowFallbackToPlaintext=true` acts like a `--ssl-mode=PREFERRED` MySQL client as described in [Command Options for Connecting to the Server](https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode)\n\n##### `allowNativePasswords`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        true\n```\n`allowNativePasswords=false` disallows the usage of MySQL native password method.\n\n##### `allowOldPasswords`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n`allowOldPasswords=true` allows the usage of the insecure old password method. This should be avoided, but is necessary in some cases. See also [the old_passwords wiki page](https://github.com/go-sql-driver/mysql/wiki/old_passwords).\n\n##### `charset`\n\n```\nType:           string\nValid Values:   \u003cname\u003e\nDefault:        none\n```\n\nSets the charset used for client-server interaction (`\"SET NAMES \u003cvalue\u003e\"`). If multiple charsets are set (separated by a comma), the following charset is used if setting the charset fails. This enables for example support for `utf8mb4` ([introduced in MySQL 5.5.3](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)) with fallback to `utf8` for older servers (`charset=utf8mb4,utf8`).\n\nSee also [Unicode Support](#unicode-support).\n\n##### `checkConnLiveness`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        true\n```\n\nOn supported platforms connections retrieved from the connection pool are checked for liveness before using them. If the check fails, the respective connection is marked as bad and the query retried with another connection.\n`checkConnLiveness=false` disables this liveness check of connections.\n\n##### `collation`\n\n```\nType:           string\nValid Values:   \u003cname\u003e\nDefault:        utf8mb4_general_ci\n```\n\nSets the collation used for client-server interaction on connection. In contrast to `charset`, `collation` does not issue additional queries. If the specified collation is unavailable on the target server, the connection will fail.\n\nA list of valid charsets for a server is retrievable with `SHOW COLLATION`.\n\nThe default collation (`utf8mb4_general_ci`) is supported from MySQL 5.5.  You should use an older collation (e.g. `utf8_general_ci`) for older MySQL.\n\nCollations for charset \"ucs2\", \"utf16\", \"utf16le\", and \"utf32\" can not be used ([ref](https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html#charset-connection-impermissible-client-charset)).\n\nSee also [Unicode Support](#unicode-support).\n\n##### `clientFoundRows`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\n`clientFoundRows=true` causes an UPDATE to return the number of matching rows instead of the number of rows changed.\n\n##### `columnsWithAlias`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\nWhen `columnsWithAlias` is true, calls to `sql.Rows.Columns()` will return the table alias and the column name separated by a dot. For example:\n\n```\nSELECT u.id FROM users as u\n```\n\nwill return `u.id` instead of just `id` if `columnsWithAlias=true`.\n\n##### `compress`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\nToggles zlib compression. false by default.\n\n##### `interpolateParams`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\nIf `interpolateParams` is true, placeholders (`?`) in calls to `db.Query()` and `db.Exec()` are interpolated into a single query string with given parameters. This reduces the number of roundtrips, since the driver has to prepare a statement, execute it with given parameters and close the statement again with `interpolateParams=false`.\n\n*This can not be used together with the multibyte encodings BIG5, CP932, GB2312, GBK or SJIS. These are rejected as they may [introduce a SQL injection vulnerability](http://stackoverflow.com/a/12118602/3430118)!*\n\n##### `loc`\n\n```\nType:           string\nValid Values:   \u003cescaped name\u003e\nDefault:        UTC\n```\n\nSets the location for time.Time values (when using `parseTime=true`). *\"Local\"* sets the system's location. See [time.LoadLocation](https://golang.org/pkg/time/#LoadLocation) for details.\n\nNote that this sets the location for time.Time values but does not change MySQL's [time_zone setting](https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html). For that see the [time_zone system variable](#system-variables), which can also be set as a DSN parameter.\n\nPlease keep in mind, that param values must be [url.QueryEscape](https://golang.org/pkg/net/url/#QueryEscape)'ed. Alternatively you can manually replace the `/` with `%2F`. For example `US/Pacific` would be `loc=US%2FPacific`.\n\n##### `timeTruncate`\n\n```\nType:           duration\nDefault:        0\n```\n\n[Truncate time values](https://pkg.go.dev/time#Duration.Truncate) to the specified duration. The value must be a decimal number with a unit suffix (*\"ms\"*, *\"s\"*, *\"m\"*, *\"h\"*), such as *\"30s\"*, *\"0.5m\"* or *\"1m30s\"*.\n\n##### `maxAllowedPacket`\n```\nType:          decimal number\nDefault:       64*1024*1024\n```\n\nMax packet size allowed in bytes. The default value is 64 MiB and should be adjusted to match the server settings. `maxAllowedPacket=0` can be used to automatically fetch the `max_allowed_packet` variable from server *on every connection*.\n\n##### `multiStatements`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\nAllow multiple statements in one query. This can be used to bach multiple queries. Use [Rows.NextResultSet()](https://pkg.go.dev/database/sql#Rows.NextResultSet) to get result of the second and subsequent queries.\n\nWhen `multiStatements` is used, `?` parameters must only be used in the first statement. [interpolateParams](#interpolateparams) can be used to avoid this limitation unless prepared statement is used explicitly.\n\nIt's possible to access the last inserted ID and number of affected rows for multiple statements by using `sql.Conn.Raw()` and the `mysql.Result`. For example:\n\n```go\nconn, _ := db.Conn(ctx)\nconn.Raw(func(conn any) error {\n  ex := conn.(driver.Execer)\n  res, err := ex.Exec(`\n  UPDATE point SET x = 1 WHERE y = 2;\n  UPDATE point SET x = 2 WHERE y = 3;\n  `, nil)\n  // Both slices have 2 elements.\n  log.Print(res.(mysql.Result).AllRowsAffected())\n  log.Print(res.(mysql.Result).AllLastInsertIds())\n})\n```\n\n##### `parseTime`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\n`parseTime=true` changes the output type of `DATE` and `DATETIME` values to `time.Time` instead of `[]byte` / `string`\nThe date or datetime like `0000-00-00 00:00:00` is converted into zero value of `time.Time`.\n\n\n##### `readTimeout`\n\n```\nType:           duration\nDefault:        0\n```\n\nI/O read timeout. The value must be a decimal number with a unit suffix (*\"ms\"*, *\"s\"*, *\"m\"*, *\"h\"*), such as *\"30s\"*, *\"0.5m\"* or *\"1m30s\"*.\n\n##### `rejectReadOnly`\n\n```\nType:           bool\nValid Values:   true, false\nDefault:        false\n```\n\n\n`rejectReadOnly=true` causes the driver to reject read-only connections. This\nis for a possible race condition during an automatic failover, where the mysql\nclient gets connected to a read-only replica after the failover.\n\nNote that this should be a fairly rare case, as an automatic failover normally\nhappens when the primary is down, and the race condition shouldn't happen\nunless it comes back up online as soon as the failover is kicked off. On the\nother hand, when this happens, a MySQL application can get stuck on a\nread-only connection until restarted. It is however fairly easy to reproduce,\nfor example, using a manual failover on AWS Aurora's MySQL-compatible cluster.\n\nIf you are not relying on read-only transactions to reject writes that aren't\nsupposed to happen, setting this on some MySQL providers (such as AWS Aurora)\nis safer for failovers.\n\nNote that ERROR 1290 can be returned for a `read-only` server and this option will\ncause a retry for that error. However the same error number is used for some\nother cases. You should ensure your application will never cause an ERROR 1290\nexcept for `read-only` mode when enabling this option.\n\n\n##### `serverPubKey`\n\n```\nType:           string\nValid Values:   \u003cname\u003e\nDefault:        none\n```\n\nServer public keys can be registered with [`mysql.RegisterServerPubKey`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterServerPubKey), which can then be used by the assigned name in the DSN.\nPublic keys are used to transmit encrypted data, e.g. for authentication.\nIf the server's public key is known, it should be set manually to avoid expensive and potentially insecure transmissions of the public key from the server to the client each time it is required.\n\n\n##### `timeout`\n\n```\nType:           duration\nDefault:        OS default\n```\n\nTimeout for establishing connections, aka dial timeout. The value must be a decimal number with a unit suffix (*\"ms\"*, *\"s\"*, *\"m\"*, *\"h\"*), such as *\"30s\"*, *\"0.5m\"* or *\"1m30s\"*.\n\n\n##### `tls`\n\n```\nType:           bool / string\nValid Values:   true, false, skip-verify, preferred, \u003cname\u003e\nDefault:        false\n```\n\n`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side) or use `preferred` to use TLS only when advertised by the server. This is similar to `skip-verify`, but additionally allows a fallback to a connection which is not encrypted. Neither `skip-verify` nor `preferred` add any reliable security. You can use a custom TLS config after registering it with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).\n\n\n##### `writeTimeout`\n\n```\nType:           duration\nDefault:        0\n```\n\nI/O write timeout. The value must be a decimal number with a unit suffix (*\"ms\"*, *\"s\"*, *\"m\"*, *\"h\"*), such as *\"30s\"*, *\"0.5m\"* or *\"1m30s\"*.\n\n##### `connectionAttributes`\n\n```\nType:           comma-delimited string of user-defined \"key:value\" pairs\nValid Values:   (\u003cname1\u003e:\u003cvalue1\u003e,\u003cname2\u003e:\u003cvalue2\u003e,...)\nDefault:        none\n```\n\n[Connection attributes](https://dev.mysql.com/doc/refman/8.0/en/performance-schema-connection-attribute-tables.html) are key-value pairs that application programs can pass to the server at connect time.\n\n##### System Variables\n\nAny other parameters are interpreted as system variables:\n  * `\u003cboolean_var\u003e=\u003cvalue\u003e`: `SET \u003cboolean_var\u003e=\u003cvalue\u003e`\n  * `\u003cenum_var\u003e=\u003cvalue\u003e`: `SET \u003cenum_var\u003e=\u003cvalue\u003e`\n  * `\u003cstring_var\u003e=%27\u003cvalue\u003e%27`: `SET \u003cstring_var\u003e='\u003cvalue\u003e'`\n\nRules:\n* The values for string variables must be quoted with `'`.\n* The values must also be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed!\n (which implies values of string variables must be wrapped with `%27`).\n\nExamples:\n  * `autocommit=1`: `SET autocommit=1`\n  * [`time_zone=%27Europe%2FParis%27`](https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html): `SET time_zone='Europe/Paris'`\n  * [`transaction_isolation=%27REPEATABLE-READ%27`](https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_transaction_isolation): `SET transaction_isolation='REPEATABLE-READ'`\n\n\n#### Examples\n```\nuser@unix(/path/to/socket)/dbname\n```\n\n```\nroot:pw@unix(/tmp/mysql.sock)/myDatabase?loc=Local\n```\n\n```\nuser:password@tcp(localhost:5555)/dbname?tls=skip-verify\u0026autocommit=true\n```\n\nTreat warnings as errors by setting the system variable [`sql_mode`](https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html):\n```\nuser:password@/dbname?sql_mode=TRADITIONAL\n```\n\nTCP via IPv6:\n```\nuser:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?timeout=90s\u0026collation=utf8mb4_unicode_ci\n```\n\nTCP on a remote host, e.g. Amazon RDS:\n```\nid:password@tcp(your-amazonaws-uri.com:3306)/dbname\n```\n\nGoogle Cloud SQL on App Engine:\n```\nuser:password@unix(/cloudsql/project-id:region-name:instance-name)/dbname\n```\n\nTCP using default port (3306) on localhost:\n```\nuser:password@tcp/dbname?charset=utf8mb4,utf8\u0026sys_var=esc%40ped\n```\n\nUse the default protocol (tcp) and host (localhost:3306):\n```\nuser:password@/dbname\n```\n\nNo Database preselected:\n```\nuser:password@/\n```\n\n\n### Connection pool and timeouts\nThe connection pool is managed by Go's database/sql package. For details on how to configure the size of the pool and how long connections stay in the pool see `*DB.SetMaxOpenConns`, `*DB.SetMaxIdleConns`, and `*DB.SetConnMaxLifetime` in the [database/sql documentation](https://golang.org/pkg/database/sql/). The read, write, and dial timeouts for each individual connection are configured with the DSN parameters [`readTimeout`](#readtimeout), [`writeTimeout`](#writetimeout), and [`timeout`](#timeout), respectively.\n\n## `ColumnType` Support\nThis driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `MEDIUMINT`, `BIGINT`.\n\n## `context.Context` Support\nGo 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.\nSee [context support in the database/sql package](https://golang.org/doc/go1.8#database_sql) for more details.\n\n\u003e [!IMPORTANT]\n\u003e The `QueryContext`, `ExecContext`, etc. variants provided by `database/sql` will cause the connection to be closed if the provided context is cancelled or timed out before the result is received by the driver.\n\n\n### `LOAD DATA LOCAL INFILE` support\nFor this feature you need direct access to the package. Therefore you must change the import path (no `_`):\n```go\nimport \"github.com/go-sql-driver/mysql\"\n```\n\nFiles must be explicitly allowed by registering them with `mysql.RegisterLocalFile(filepath)` (recommended) or the allowlist check must be deactivated by using the DSN parameter `allowAllFiles=true` ([*Might be insecure!*](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-local)).\n\nTo use a `io.Reader` a handler function must be registered with `mysql.RegisterReaderHandler(name, handler)` which returns a `io.Reader` or `io.ReadCloser`. The Reader is available with the filepath `Reader::\u003cname\u003e` then. Choose different names for different handlers and `DeregisterReaderHandler` when you don't need it anymore.\n\nSee the [godoc of Go-MySQL-Driver](https://godoc.org/github.com/go-sql-driver/mysql \"golang mysql driver documentation\") for details.\n\n\n### `time.Time` support\nThe default internal output type of MySQL `DATE` and `DATETIME` values is `[]byte` which allows you to scan the value into a `[]byte`, `string` or `sql.RawBytes` variable in your program.\n\nHowever, many want to scan MySQL `DATE` and `DATETIME` values into `time.Time` variables, which is the logical equivalent in Go to `DATE` and `DATETIME` in MySQL. You can do that by changing the internal output type from `[]byte` to `time.Time` with the DSN parameter `parseTime=true`. You can set the default [`time.Time` location](https://golang.org/pkg/time/#Location) with the `loc` DSN parameter.\n\n**Caution:** As of Go 1.1, this makes `time.Time` the only variable type you can scan `DATE` and `DATETIME` values into. This breaks for example [`sql.RawBytes` support](https://github.com/go-sql-driver/mysql/wiki/Examples#rawbytes).\n\n\n### Unicode support\nSince version 1.5 Go-MySQL-Driver automatically uses the collation ` utf8mb4_general_ci` by default.\n\nOther charsets / collations can be set using the [`charset`](#charset) or [`collation`](#collation) DSN parameter.\n\n- When only the `charset` is specified, the `SET NAMES \u003ccharset\u003e` query is sent and the server's default collation is used.\n- When both the `charset` and `collation` are specified, the `SET NAMES \u003ccharset\u003e COLLATE \u003ccollation\u003e` query is sent.\n- When only the `collation` is specified, the collation is specified in the protocol handshake and the `SET NAMES` query is not sent. This can save one roundtrip, but note that the server may ignore the specified collation silently and use the server's default charset/collation instead.\n\nSee http://dev.mysql.com/doc/refman/8.0/en/charset-unicode.html for more details on MySQL's Unicode support.\n\n## Testing / Development\nTo run the driver tests you may need to adjust the configuration. See the [Testing Wiki-Page](https://github.com/go-sql-driver/mysql/wiki/Testing \"Testing\") for details.\n\nGo-MySQL-Driver is not feature-complete yet. Your help is very appreciated.\nIf you want to contribute, you can work on an [open issue](https://github.com/go-sql-driver/mysql/issues?state=open) or review a [pull request](https://github.com/go-sql-driver/mysql/pulls).\n\nSee the [Contribution Guidelines](https://github.com/go-sql-driver/mysql/blob/master/.github/CONTRIBUTING.md) for details.\n\n---------------------------------------\n\n## License\nGo-MySQL-Driver is licensed under the [Mozilla Public License Version 2.0](https://raw.github.com/go-sql-driver/mysql/master/LICENSE)\n\nMozilla summarizes the license scope as follows:\n\u003e MPL: The copyleft applies to any files containing MPLed code.\n\n\nThat means:\n  * You can **use** the **unchanged** source code both in private and commercially.\n  * When distributing, you **must publish** the source code of any **changed files** licensed under the MPL 2.0 under a) the MPL 2.0 itself or b) a compatible license (e.g. GPL 3.0 or Apache License 2.0).\n  * You **needn't publish** the source code of your library as long as the files licensed under the MPL 2.0 are **unchanged**.\n\nPlease read the [MPL 2.0 FAQ](https://www.mozilla.org/en-US/MPL/2.0/FAQ/) if you have further questions regarding the license.\n\nYou can read the full terms here: [LICENSE](https://raw.github.com/go-sql-driver/mysql/master/LICENSE).\n\n![Go Gopher and MySQL Dolphin](https://raw.github.com/wiki/go-sql-driver/mysql/go-mysql-driver_m.jpg \"Golang Gopher transporting the MySQL Dolphin in a wheelbarrow\")\n","funding_links":[],"categories":["数据库驱动","數據庫驅動"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGo-sql-driver%2Fmysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGo-sql-driver%2Fmysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGo-sql-driver%2Fmysql/lists"}