package mysql

Import Path
	github.com/go-sql-driver/mysql (on go.dev)

Dependency Relation
	imports 29 packages, and imported by one package

Involved Source Files
	    auth.go
	    buffer.go
	    collations.go
	    conncheck.go
	    connection.go
	    connector.go
	    const.go
	d-> driver.go
	    dsn.go
	    errors.go
	    fields.go
	    infile.go
	    nulltime.go
	    nulltime_go113.go
	    packets.go
	    result.go
	    rows.go
	    statement.go
	    transaction.go
	    utils.go

Exported Type Names

type Config (struct) Config is a configuration parsed from a DSN string. If a new Config is created instead of being parsed from a DSN string, the NewConfig function should be used, which sets default values. Addr string AllowAllFiles bool AllowCleartextPasswords bool AllowNativePasswords bool AllowOldPasswords bool CheckConnLiveness bool ClientFoundRows bool Collation string ColumnsWithAlias bool DBName string InterpolateParams bool Loc *time.Location MaxAllowedPacket int MultiStatements bool Net string Params map[string]string ParseTime bool Passwd string ReadTimeout time.Duration RejectReadOnly bool ServerPubKey string TLSConfig string Timeout time.Duration User string WriteTimeout time.Duration (*T) Clone() *Config (*T) FormatDSN() string func NewConfig() *Config func ParseDSN(dsn string) (cfg *Config, err error) func (*Config).Clone() *Config func NewConnector(cfg *Config) (driver.Connector, error)
type DialContextFunc (func) DialContextFunc is a function which can be used to establish the network connection. Custom dial functions must be registered with RegisterDialContext func RegisterDialContext(net string, dial DialContextFunc)
type DialFunc (func) DialFunc is a function which can be used to establish the network connection. Custom dial functions must be registered with RegisterDial Deprecated: users should register a DialContextFunc instead func RegisterDial(network string, dial DialFunc)
type Logger (interface) Logger is used to log critical error messages. (T) Print(v ...interface{}) log.(*Logger) func SetLogger(logger Logger) error
type MySQLDriver (struct) MySQLDriver is exported to make the driver directly accessible. In general the driver is used via the database/sql package. (T) Open(dsn string) (driver.Conn, error) (T) OpenConnector(dsn string) (driver.Connector, error) T : database/sql/driver.Driver T : database/sql/driver.DriverContext
type MySQLError (struct) MySQLError is an error type which represents a single MySQL error Message string Number uint16 (*T) Error() string *T : error
type NullTime sql.NullTime (struct) NullTime represents a time.Time that may be NULL. NullTime implements the Scanner interface so it can be used as a scan destination: var nt NullTime err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt) ... if nt.Valid { // use nt.Time } else { // NULL value } This NullTime implementation is not driver-specific Time time.Time Valid bool (*T) Scan(value interface{}) (err error) (T) Value() (driver.Value, error) *T : database/sql.Scanner T : database/sql/driver.Valuer
Exported Values
func DeregisterLocalFile(filePath string) DeregisterLocalFile removes the given filepath from the whitelist.
func DeregisterReaderHandler(name string) DeregisterReaderHandler removes the ReaderHandler function with the given name from the registry.
func DeregisterServerPubKey(name string) DeregisterServerPubKey removes the public key registered with the given name.
func DeregisterTLSConfig(key string) DeregisterTLSConfig removes the tls.Config associated with key.
var ErrBusyBuffer error Various errors the driver might return. Can change between driver versions.
var ErrCleartextPassword error Various errors the driver might return. Can change between driver versions.
var ErrInvalidConn error Various errors the driver might return. Can change between driver versions.
var ErrMalformPkt error Various errors the driver might return. Can change between driver versions.
var ErrNativePassword error Various errors the driver might return. Can change between driver versions.
var ErrNoTLS error Various errors the driver might return. Can change between driver versions.
var ErrOldPassword error Various errors the driver might return. Can change between driver versions.
var ErrOldProtocol error Various errors the driver might return. Can change between driver versions.
var ErrPktSync error Various errors the driver might return. Can change between driver versions.
var ErrPktSyncMul error Various errors the driver might return. Can change between driver versions.
var ErrPktTooLarge error Various errors the driver might return. Can change between driver versions.
var ErrUnknownPlugin error Various errors the driver might return. Can change between driver versions.
func NewConfig() *Config NewConfig creates a new Config and sets default values.
func NewConnector(cfg *Config) (driver.Connector, error) NewConnector returns new driver.Connector.
func ParseDSN(dsn string) (cfg *Config, err error) ParseDSN parses the DSN string to a Config
func RegisterDial(network string, dial DialFunc) RegisterDial registers a custom dial function. It can then be used by the network address mynet(addr), where mynet is the registered new network. addr is passed as a parameter to the dial function. Deprecated: users should call RegisterDialContext instead
func RegisterDialContext(net string, dial DialContextFunc) RegisterDialContext registers a custom dial function. It can then be used by the network address mynet(addr), where mynet is the registered new network. The current context for the connection and its address is passed to the dial function.
func RegisterLocalFile(filePath string) RegisterLocalFile adds the given file to the file whitelist, so that it can be used by "LOAD DATA LOCAL INFILE <filepath>". Alternatively you can allow the use of all local files with the DSN parameter 'allowAllFiles=true' filePath := "/home/gopher/data.csv" mysql.RegisterLocalFile(filePath) err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo") if err != nil { ...
func RegisterReaderHandler(name string, handler func() io.Reader) RegisterReaderHandler registers a handler function which is used to receive a io.Reader. The Reader can be used by "LOAD DATA LOCAL INFILE Reader::<name>". If the handler returns a io.ReadCloser Close() is called when the request is finished. mysql.RegisterReaderHandler("data", func() io.Reader { var csvReader io.Reader // Some Reader that returns CSV data ... // Open Reader here return csvReader }) err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo") if err != nil { ...
func RegisterServerPubKey(name string, pubKey *rsa.PublicKey) RegisterServerPubKey registers a server RSA public key which can be used to send data in a secure manner to the server without receiving the public key in a potentially insecure way from the server first. Registered keys can afterwards be used adding serverPubKey=<name> to the DSN. Note: The provided rsa.PublicKey instance is exclusively owned by the driver after registering it and may not be modified. data, err := ioutil.ReadFile("mykey.pem") if err != nil { log.Fatal(err) } block, _ := pem.Decode(data) if block == nil || block.Type != "PUBLIC KEY" { log.Fatal("failed to decode PEM block containing public key") } pub, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { log.Fatal(err) } if rsaPubKey, ok := pub.(*rsa.PublicKey); ok { mysql.RegisterServerPubKey("mykey", rsaPubKey) } else { log.Fatal("not a RSA public key") }
func RegisterTLSConfig(key string, config *tls.Config) error RegisterTLSConfig registers a custom tls.Config to be used with sql.Open. Use the key as a value in the DSN where tls=value. Note: The provided tls.Config is exclusively owned by the driver after registering it. rootCertPool := x509.NewCertPool() pem, err := ioutil.ReadFile("/path/ca-cert.pem") if err != nil { log.Fatal(err) } if ok := rootCertPool.AppendCertsFromPEM(pem); !ok { log.Fatal("Failed to append PEM.") } clientCert := make([]tls.Certificate, 0, 1) certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem") if err != nil { log.Fatal(err) } clientCert = append(clientCert, certs) mysql.RegisterTLSConfig("custom", &tls.Config{ RootCAs: rootCertPool, Certificates: clientCert, }) db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
func SetLogger(logger Logger) error SetLogger is used to set the logger for critical errors. The initial logger is os.Stderr.