Documentation ¶
Index ¶
- Constants
- func AppendDateTime(buf []byte, t time.Time) ([]byte, error)
- func DeregisterServerPubKey(name string)
- func DeregisterTLSConfig(key string)
- func Escape(sql string) string
- func GetDefaultFieldLengthAndDecimal(tp mysql.FieldType) (flen int, decimal int)
- func GetDefaultFieldLengthAndDecimalForCast(tp mysql.FieldType) (flen int, decimal int)
- func IsIntegerType(tp mysql.FieldType) bool
- func NewListener(conf *config.Listener) (proto.Listener, error)
- func ParseErrorPacket(data []byte) error
- func PutLengthEncodedInt(n uint64) []byte
- func PutLengthEncodedString(b []byte) []byte
- func RandomBuf(size int) ([]byte, error)
- func RegisterServerPubKey(name string, pubKey *rsa.PublicKey)
- func RegisterTLSConfig(key string, config *tls.Config) error
- type BackendConnection
- func (conn *BackendConnection) Close()
- func (conn *BackendConnection) Connect(ctx context.Context) error
- func (conn *BackendConnection) DBName() string
- func (conn *BackendConnection) DrainResults() error
- func (conn *BackendConnection) ExecuteWithWarningCount(query string, wantFields bool) (result proto.Result, err error)
- func (conn *BackendConnection) ExecuteWithWarningCountIterRow(query string) (result proto.Result, err error)
- func (conn *BackendConnection) GetDatabaseConn() *Conn
- func (conn *BackendConnection) PersistVariables() (map[string]proto.Value, error)
- func (conn *BackendConnection) Ping() error
- func (conn *BackendConnection) PrepareExecute(query string, data []byte) (proto.Result, error)
- func (conn *BackendConnection) PrepareExecuteArgs(query string, args []proto.Value) (proto.Result, error)
- func (conn *BackendConnection) PrepareQuery(query string, data []byte) (proto.Result, error)
- func (conn *BackendConnection) PrepareQueryArgs(query string, data []proto.Value) (proto.Result, error)
- func (conn *BackendConnection) ReadColumnDefinition(field *Field, index int) error
- func (conn *BackendConnection) ReadColumnDefinitionType(field *Field, index int) error
- func (conn *BackendConnection) ReadColumnDefinitions() ([]proto.Field, error)
- func (conn *BackendConnection) ReadQueryResult(wantFields bool) proto.Result
- func (conn *BackendConnection) ReadQueryRow() *RawResult
- func (conn *BackendConnection) ResetVariables() error
- func (conn *BackendConnection) SyncVariables(vars map[string]proto.Value) error
- func (conn *BackendConnection) WriteComFieldList(table string, wildcard string) error
- func (conn *BackendConnection) WriteComInitDB(db string) error
- func (conn *BackendConnection) WriteComQuery(query string) error
- func (conn *BackendConnection) WriteComSetOption(operation uint16) error
- type BackendStatement
- type BinaryRow
- type Config
- type Conn
- func (c *Conn) CharacterSet() uint8
- func (c *Conn) Close()
- func (c *Conn) DefColumnDefinition(field *Field) []byte
- func (c *Conn) GetNetConn() net.Conn
- func (c *Conn) GetTLSClientCerts() []*x509.Certificate
- func (c *Conn) ID() uint32
- func (c *Conn) IsClosed() bool
- func (c *Conn) ReadPacket() ([]byte, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) Schema() string
- func (c *Conn) ServerVersion() string
- func (c *Conn) SetSchema(schema string)
- func (c *Conn) SetTenant(t string)
- func (c *Conn) SetTransientVariables(v map[string]proto.Value)
- func (c *Conn) String() string
- func (c *Conn) Tenant() string
- func (c *Conn) TransientVariables() map[string]proto.Value
- type Connector
- type Field
- func (mf *Field) DatabaseName() string
- func (mf *Field) DatabaseTypeName() string
- func (mf *Field) DecimalSize() (int64, int64, bool)
- func (mf *Field) FieldType() mysql.FieldType
- func (mf *Field) Length() (length int64, ok bool)
- func (mf *Field) Name() string
- func (mf *Field) Nullable() (nullable, ok bool)
- func (mf *Field) OriginName() string
- func (mf *Field) ScanType() reflect.Type
- func (mf *Field) SetName(name string)
- func (mf *Field) SetOrgName(name string)
- func (mf *Field) TableName() string
- type Listener
- type RawBytes
- type RawResult
- func (rr *RawResult) Close() error
- func (rr *RawResult) Dataset() (proto.Dataset, error)
- func (rr *RawResult) Discard() (err error)
- func (rr *RawResult) Fields() ([]proto.Field, error)
- func (rr *RawResult) LastInsertId() (uint64, error)
- func (rr *RawResult) Next() (row proto.Row, err error)
- func (rr *RawResult) RowsAffected() (uint64, error)
- func (rr *RawResult) SetCloser(closer func() error)
- func (rr *RawResult) Warn() (uint16, error)
- type Scanner
- type ServerConfig
- type TextRow
Constants ¶
const (
UserMaxAllowedPacket uint32 = 1 << iota
)
Variables ¶
This section is empty.
Functions ¶
func DeregisterServerPubKey ¶
func DeregisterServerPubKey(name string)
DeregisterServerPubKey removes the public key registered with the given name.
func DeregisterTLSConfig ¶
func DeregisterTLSConfig(key string)
DeregisterTLSConfig removes the tls.Config associated with key.
func GetDefaultFieldLengthAndDecimal ¶
GetDefaultFieldLengthAndDecimal returns the default display length (flen) and decimal length for column. Call this when no Flen assigned in ddl. or column value is calculated from an expression. For example: "select count(*) from t;", the column type is int64 and Flen in ResultField will be 21. See https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html
func GetDefaultFieldLengthAndDecimalForCast ¶
GetDefaultFieldLengthAndDecimalForCast returns the default display length (flen) and decimal length for casted column when flen or decimal is not specified.
func IsIntegerType ¶
IsIntegerType indicate whether tp is an integer type.
func ParseErrorPacket ¶
ParseErrorPacket parses the error packet and returns a SQLError.
func PutLengthEncodedInt ¶
func PutLengthEncodedString ¶
func RegisterServerPubKey ¶
RegisterServerPubKey registers a server RSA public key which can be used to send Content 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.
Content, err := ioutil.ReadFile("mykey.pem") if err != nil { log.Fatal(err) } block, _ := pem.Decode(Content) 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 ¶
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")
Types ¶
type BackendConnection ¶
type BackendConnection struct {
// contains filtered or unexported fields
}
func (*BackendConnection) Close ¶
func (conn *BackendConnection) Close()
func (*BackendConnection) Connect ¶
func (conn *BackendConnection) Connect(ctx context.Context) error
func (*BackendConnection) DBName ¶
func (conn *BackendConnection) DBName() string
func (*BackendConnection) DrainResults ¶
func (conn *BackendConnection) DrainResults() error
DrainResults will read all packets for a result set and ignore them.
func (*BackendConnection) ExecuteWithWarningCount ¶
func (conn *BackendConnection) ExecuteWithWarningCount(query string, wantFields bool) (result proto.Result, err error)
ExecuteWithWarningCount is for fetching results and a warning count Note: In a future iteration this should be abolished and merged into the Executed API.
func (*BackendConnection) ExecuteWithWarningCountIterRow ¶
func (conn *BackendConnection) ExecuteWithWarningCountIterRow(query string) (result proto.Result, err error)
ExecuteWithWarningCountIterRow is for fetching results and a warning count Note: In a future iteration this should be abolished and merged into Execute API.
func (*BackendConnection) GetDatabaseConn ¶
func (conn *BackendConnection) GetDatabaseConn() *Conn
func (*BackendConnection) PersistVariables ¶
func (conn *BackendConnection) PersistVariables() (map[string]proto.Value, error)
PersistVariables returns the persisted variables from remote mysql.
func (*BackendConnection) Ping ¶
func (conn *BackendConnection) Ping() error
Ping implements mysql ping command.
func (*BackendConnection) PrepareExecute ¶
func (*BackendConnection) PrepareExecuteArgs ¶
func (*BackendConnection) PrepareQuery ¶
func (*BackendConnection) PrepareQueryArgs ¶
func (*BackendConnection) ReadColumnDefinition ¶
func (conn *BackendConnection) ReadColumnDefinition(field *Field, index int) error
ReadColumnDefinition reads the next Column Definition packet. Returns a SQLError. https://dev.mysql.com/doc/internals/en/com-query-response.html#column-definition
func (*BackendConnection) ReadColumnDefinitionType ¶
func (conn *BackendConnection) ReadColumnDefinitionType(field *Field, index int) error
ReadColumnDefinitionType is a faster version of ReadColumnDefinition that only fills in the Type. Returns a SQLError.
func (*BackendConnection) ReadColumnDefinitions ¶
func (conn *BackendConnection) ReadColumnDefinitions() ([]proto.Field, error)
func (*BackendConnection) ReadQueryResult ¶
func (conn *BackendConnection) ReadQueryResult(wantFields bool) proto.Result
ReadQueryResult gets the result from the last written query.
func (*BackendConnection) ReadQueryRow ¶
func (conn *BackendConnection) ReadQueryRow() *RawResult
ReadQueryRow returns iterator, and the line reads the results set
func (*BackendConnection) ResetVariables ¶
func (conn *BackendConnection) ResetVariables() error
ResetVariables resets transient variables.
func (*BackendConnection) SyncVariables ¶
func (conn *BackendConnection) SyncVariables(vars map[string]proto.Value) error
SyncVariables sync local transient variables with upstream mysql.
The sync logic:
CLIENT ----ConnA----> ARANA ----ConnB----> MySQL
| | transient-vars persist-vars \ / \ / >>> SYNC <<<
func (*BackendConnection) WriteComFieldList ¶
func (conn *BackendConnection) WriteComFieldList(table string, wildcard string) error
WriteComFieldList https://dev.mysql.com/doc/internals/en/com-field-list.html
func (*BackendConnection) WriteComInitDB ¶
func (conn *BackendConnection) WriteComInitDB(db string) error
WriteComInitDB changes the default database to use. Client -> Server. Returns SQLError(CRServerGone) if it can't.
func (*BackendConnection) WriteComQuery ¶
func (conn *BackendConnection) WriteComQuery(query string) error
WriteComQuery writes a query for the server to execute. Client -> Server. Returns SQLError(CRServerGone) if it can't.
func (*BackendConnection) WriteComSetOption ¶
func (conn *BackendConnection) WriteComSetOption(operation uint16) error
WriteComSetOption changes the connection's capability of executing multi statements. Returns SQLError(CRServerGone) if it can't.
type BackendStatement ¶
type BackendStatement struct {
// contains filtered or unexported fields
}
type Config ¶
type Config struct { User string // Username Passwd string // Password (requires User) Net string // Network type Addr string // Network address (requires Net) DBName string // Database name Params map[string]string // Connection parameters Collation string // Connection collation Loc *time.Location // Location for time.Time values MaxAllowedPacket int // Max packet size allowed ServerPubKey string // Server public key name TLSConfig string // TLS configuration name Timeout time.Duration // Dial timeout ReadTimeout time.Duration // I/O read timeout WriteTimeout time.Duration // I/O write timeout AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE AllowCleartextPasswords bool // Allows the cleartext client side plugin AllowNativePasswords bool // Allows the native password authentication method AllowOldPasswords bool // Allows the old insecure password method CheckConnLiveness bool // Check connections for liveness before using them ClientFoundRows bool // Return number of matching rows instead of rows changed ColumnsWithAlias bool // Prepend table alias to column names InterpolateParams bool // Interpolate placeholders into query string MultiStatements bool // Allow multiple statements in one query ParseTime bool // Parse time values to time.Time RejectReadOnly bool // Reject read-only connections DisableClientDeprecateEOF bool // Disable client deprecate EOF // contains filtered or unexported fields }
func NewConfig ¶
func NewConfig() *Config
NewConfig creates a new ServerConfig and sets default values.
type Conn ¶
type Conn struct { // StatusFlags are the status flags we will base our returned flags on. // This is a bit field, with values documented in constants.go. // An interesting value here would be ServerStatusAutocommit. // It is only used by the server. These flags can be changed // by Handler methods. StatusFlags uint16 // Capabilities is the current set of features this connection // is using. It is the features that are both supported by // the client and the server, and currently in use. // It is set during the initial handshake. // // It is only used for CapabilityClientDeprecateEOF // and CapabilityClientFoundRows. Capabilities uint32 // contains filtered or unexported fields }
Conn is a connection between a client and a server, using the MySQL binary protocol. It is built on top of an existing net.Conn, that has already been established.
Use Connect on the client side to create a connection. Use NewListener to create a server side and listen for connections.
func (*Conn) CharacterSet ¶
func (*Conn) Close ¶
func (c *Conn) Close()
Close closes the connection. It can be called from a different go routine to interrupt the current connection.
func (*Conn) DefColumnDefinition ¶
func (*Conn) GetNetConn ¶
func (*Conn) GetTLSClientCerts ¶
func (c *Conn) GetTLSClientCerts() []*x509.Certificate
GetTLSClientCerts gets TLS certificates.
func (*Conn) IsClosed ¶
IsClosed returns true if this connection was ever closed by the Close() method. Note if the other side closes the connection, but Close() wasn't called, this will return false.
func (*Conn) ReadPacket ¶
ReadPacket reads a packet from the underlying connection. it is the public API version, that returns a SQLError. The memory for the packet is always allocated, and it is owned by the caller after this function returns.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the underlying socket RemoteAddr().
func (*Conn) ServerVersion ¶
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
func NewConnector ¶
func (*Connector) NewBackendConnection ¶
func (c *Connector) NewBackendConnection(ctx context.Context) (*BackendConnection, error)
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
func (*Field) DatabaseName ¶
func (*Field) DatabaseTypeName ¶
func (*Field) OriginName ¶
func (*Field) SetOrgName ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
func (*Listener) ExecuteCommand ¶
func (*Listener) SetExecutor ¶
func (*Listener) ValidateHash ¶
type RawResult ¶
type RawResult struct {
// contains filtered or unexported fields
}
func (*RawResult) LastInsertId ¶
func (*RawResult) RowsAffected ¶
type Scanner ¶
type Scanner interface { // Scan assigns a value from a database driver. // // The src value will be of one of the following types: // // int64 // float64 // bool // []byte // string // time.Time // nil - for NULL values // // An error should be returned if the value cannot be stored // without loss of information. // // Reference types such as []byte are only valid until the next call to Scan // and should not be retained. Their underlying memory is owned by the driver. // If retention is necessary, copy their values before the next call to Scan. Scan(src interface{}) error }
Scanner is an interface used by Scan.
type ServerConfig ¶
type ServerConfig struct {
ServerVersion string `yaml:"server_version" json:"server_version"`
}