A MySQL-Driver for Go's database/sql package which properly implement context cancelation for MySQL.
See Article for details of the behind-the-scenes magic.
- Wrapper over standard Go MySQL Driver
- Automatic killing queries on context cancellation
- Automatic connection pooling (by database/sql package)
The same as for imported version of Go MySQL Driver
Simple install the package to your $GOPATH with the go tool from shell:
$ go get -u github.com/dati-mipt/mysql-go
Make sure Git is installed on your machine and in your system's PATH
.
This is 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 mysqlc
as driverName
and a valid DSN as dataSourceName
:
import (
"database/sql"
"time"
_ "github.com/dati-mipt/mysql-go"
)
// ...
db, err := sql.Open("mysqlc", "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 Wiki of standard mysql driver.
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&...¶mN=valueN]
Parameters are case-sensitive!
In addition to Go MySQL Driver parameters, this wrapper introduces some new params:
Type: decimal number
Default: 1
Size of connection pool for killing queries.
Type: duration
Default: 5s
Timeout of kill operation.
Cancel the context. This will send a KILL
signal to MySQL automatically.
The license is a modified MIT license. Refer to LICENSE
file for more details.
© 2018-19 PJ Engineering and Business Solutions Pty. Ltd.
Feel free to enhance features by issuing pull-requests.