Documentation ¶
Overview ¶
Package mysql is a library to support MySQL binary protocol, both client and server sides. It also supports binlog event parsing.
Index ¶
- Constants
- Variables
- func BaseShowTablesRow(tableName string, isView bool, comment string) []sqltypes.Value
- func DecodeMysqlNativePasswordHex(hexEncodedPassword string) ([]byte, error)
- func EncryptPasswordWithPublicKey(salt []byte, password []byte, pub *rsa.PublicKey) ([]byte, error)
- func ExecuteFetchMap(conn *Conn, query string) (map[string]string, error)
- func FlagsForColumn(t sqltypes.Type, col collations.ID) uint32
- func GetCharset(conn *Conn) (*binlogdatapb.Charset, error)
- func GetFlavor(serverVersion string, flavorFunc func() flavor) (f flavor, capableOf capabilities.CapableOf, canonicalVersion string)
- func InitAuthServerClientCert(clientcertAuthMethod string)
- func InitAuthServerStatic(mysqlAuthServerStaticFile, mysqlAuthServerStaticString string, ...)
- func IsNum(typ uint8) bool
- func MatchSourceHost(remoteAddr net.Addr, targetSourceHost string) bool
- func ParseConfig(jsonBytes []byte, config *map[string][]*AuthServerStaticEntry) error
- func ParseErrorPacket(data []byte) error
- func RegisterAuthServer(name string, authServer AuthServer)
- func RegisterAuthServerStaticFromParams(file, jsonConfig string, reloadInterval time.Duration)
- func ScrambleCachingSha2Password(salt []byte, password []byte) []byte
- func ScrambleMysqlNativePassword(salt, password []byte) []byte
- func ServerVersionCapableOf(serverVersion string) (capableOf capabilities.CapableOf)
- func SetCharset(conn *Conn, cs *binlogdatapb.Charset) error
- func ShowPrimaryRow(tableName, colName string) []sqltypes.Value
- func VerifyHashedCachingSha2Password(reply, salt, hashedCachingSha2Password []byte) bool
- func VerifyHashedMysqlNativePassword(reply, salt, hashedNativePassword []byte) bool
- type AuthMethod
- func NewMysqlClearAuthMethod(layer PlainTextStorage, validator UserValidator) AuthMethod
- func NewMysqlDialogAuthMethod(layer PlainTextStorage, validator UserValidator, msg string) AuthMethod
- func NewMysqlNativeAuthMethod(layer HashStorage, validator UserValidator) AuthMethod
- func NewSha2CachingAuthMethod(layer1 CachingStorage, layer2 PlainTextStorage, validator UserValidator) AuthMethod
- type AuthMethodDescription
- type AuthServer
- type AuthServerClientCert
- func (asl *AuthServerClientCert) AuthMethods() []AuthMethod
- func (asl *AuthServerClientCert) DefaultAuthMethodDescription() AuthMethodDescription
- func (asl *AuthServerClientCert) HandleUser(user string) bool
- func (asl *AuthServerClientCert) UserEntryWithPassword(conn *Conn, user string, password string, remoteAddr net.Addr) (Getter, error)
- type AuthServerNone
- func (a *AuthServerNone) AuthMethods() []AuthMethod
- func (a *AuthServerNone) DefaultAuthMethodDescription() AuthMethodDescription
- func (a *AuthServerNone) HandleUser(user string) bool
- func (a *AuthServerNone) UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error)
- type AuthServerStatic
- func (a *AuthServerStatic) AuthMethods() []AuthMethod
- func (a *AuthServerStatic) DefaultAuthMethodDescription() AuthMethodDescription
- func (a *AuthServerStatic) HandleUser(user string) bool
- func (a *AuthServerStatic) UserEntryWithCacheHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, CacheState, error)
- func (a *AuthServerStatic) UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error)
- func (a *AuthServerStatic) UserEntryWithPassword(conn *Conn, user string, password string, remoteAddr net.Addr) (Getter, error)
- type AuthServerStaticEntry
- type BinlogEvent
- func NewDeleteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent
- func NewFakeRotateEvent(f BinlogFormat, s *FakeBinlogStream, filename string) BinlogEvent
- func NewFormatDescriptionEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
- func NewHeartbeatEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
- func NewHeartbeatEventWithLogFile(f BinlogFormat, s *FakeBinlogStream, filename string) BinlogEvent
- func NewIntVarEvent(f BinlogFormat, s *FakeBinlogStream, typ byte, value uint64) BinlogEvent
- func NewInvalidEvent() BinlogEvent
- func NewInvalidFormatDescriptionEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
- func NewInvalidQueryEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
- func NewMariaDBGTIDEvent(f BinlogFormat, s *FakeBinlogStream, gtid replication.MariadbGTID, ...) BinlogEvent
- func NewMariadbBinlogEvent(buf []byte) BinlogEvent
- func NewMariadbBinlogEventWithSemiSyncInfo(buf []byte, semiSyncAckRequested bool) BinlogEvent
- func NewMysql56BinlogEvent(buf []byte) BinlogEvent
- func NewMysql56BinlogEventWithSemiSyncInfo(buf []byte, semiSyncAckRequested bool) BinlogEvent
- func NewQueryEvent(f BinlogFormat, s *FakeBinlogStream, q Query) BinlogEvent
- func NewRotateEvent(f BinlogFormat, s *FakeBinlogStream, position uint64, filename string) BinlogEvent
- func NewTableMapEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, tm *TableMap) BinlogEvent
- func NewUpdateRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent
- func NewWriteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent
- func NewXIDEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
- type BinlogFormat
- type Bitmap
- type CacheState
- type CachingStorage
- type Conn
- func (c *Conn) AnalyzeSemiSyncAckRequest(buf []byte) (strippedBuf []byte, ackRequested bool, err error)
- func (c *Conn) BaseShowTables() string
- func (c *Conn) BaseShowTablesWithSizes() string
- func (c *Conn) CancelCtx()
- func (c *Conn) Close()
- func (c *Conn) CloseResult()
- func (c *Conn) ConnCheck() error
- func (c *Conn) ExecuteFetch(query string, maxrows int, wantfields bool) (result *sqltypes.Result, err error)
- func (c *Conn) ExecuteFetchMulti(query string, maxrows int, wantfields bool) (result *sqltypes.Result, more bool, err error)
- func (c *Conn) ExecuteFetchWithWarningCount(query string, maxrows int, wantfields bool) (result *sqltypes.Result, warnings uint16, err error)
- func (c *Conn) ExecuteStreamFetch(query string) (err error)
- func (c *Conn) FetchNext(in []sqltypes.Value) ([]sqltypes.Value, error)
- func (c *Conn) Fields() ([]*querypb.Field, error)
- func (c *Conn) GetGTIDMode() (string, error)
- func (c *Conn) GetGTIDPurged() (replication.Position, error)
- func (c *Conn) GetRawConn() net.Conn
- func (c *Conn) GetServerUUID() (string, error)
- func (c *Conn) GetTLSClientCerts() []*x509.Certificate
- func (c *Conn) ID() int64
- func (c *Conn) IsClosed() bool
- func (c *Conn) IsMariaDB() bool
- func (c *Conn) IsMarkedForClose() bool
- func (c *Conn) IsShuttingDown() bool
- func (c *Conn) IsUnixSocket() bool
- func (c *Conn) MarkForClose()
- func (c *Conn) Ping() error
- func (c *Conn) PrimaryFilePosition() (replication.Position, error)
- func (c *Conn) PrimaryPosition() (replication.Position, error)
- func (c *Conn) ReadBinlogEvent() (BinlogEvent, error)
- func (c *Conn) ReadPacket() ([]byte, error)
- func (c *Conn) ReadQueryResult(maxrows int, wantfields bool) (*sqltypes.Result, bool, uint16, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) ResetReplicationCommands() []string
- func (c *Conn) ResetReplicationParametersCommands() []string
- func (c *Conn) RestartReplicationCommands() []string
- func (c *Conn) SemiSyncExtensionLoaded() bool
- func (c *Conn) SendBinlogDumpCommand(serverID uint32, binlogFilename string, startPos replication.Position) error
- func (c *Conn) SendSemiSyncAck(binlogFilename string, binlogPos uint64) error
- func (c *Conn) ServerVersionAtLeast(parts ...int) (bool, error)
- func (c *Conn) SetReplicationPositionCommands(pos replication.Position) []string
- func (c *Conn) SetReplicationSourceCommand(params *ConnParams, host string, port int32, connectRetry int) string
- func (c *Conn) ShowPrimaryStatus() (replication.PrimaryStatus, error)
- func (c *Conn) ShowReplicationStatus() (replication.ReplicationStatus, error)
- func (c *Conn) StartReplicationCommand() string
- func (c *Conn) StartReplicationUntilAfterCommand(pos replication.Position) string
- func (c *Conn) StartSQLThreadCommand() string
- func (c *Conn) StartSQLThreadUntilAfterCommand(pos replication.Position) string
- func (c *Conn) StopIOThreadCommand() string
- func (c *Conn) StopReplicationCommand() string
- func (c *Conn) StopSQLThreadCommand() string
- func (c *Conn) String() string
- func (c *Conn) SupportsCapability(capability capabilities.FlavorCapability) (bool, error)
- func (c *Conn) TLSEnabled() bool
- func (c *Conn) UpdateCancelCtx(cancel context.CancelFunc)
- func (c *Conn) WaitUntilFilePosition(ctx context.Context, pos replication.Position) error
- func (c *Conn) WaitUntilPosition(ctx context.Context, pos replication.Position) error
- func (c *Conn) WriteBinlogEvent(ev BinlogEvent, semiSyncEnabled bool) error
- func (c *Conn) WriteComBinlogDump(serverID uint32, binlogFilename string, binlogPos uint32, flags uint16) error
- func (c *Conn) WriteComBinlogDumpGTID(serverID uint32, binlogFilename string, binlogPos uint64, flags uint16, ...) error
- func (c *Conn) WriteComQuery(query string) error
- func (c *Conn) WriteErrorAndLog(format string, args ...interface{}) bool
- type ConnParams
- type FakeBinlogStream
- type Getter
- type Handler
- type HashStorage
- type Listener
- type ListenerConfig
- type NoneGetter
- type PacketComStmtPrepareOK
- type PacketOK
- type PlainTextStorage
- type PrepareData
- type Query
- type Row
- type Rows
- type StaticUserData
- type TableMap
- type TransactionPayload
- type UnimplementedHandler
- type UserValidator
Constants ¶
const ( BinlogDumpNonBlock = 0x01 BinlogThroughPosition = 0x02 BinlogThroughGTID = 0x04 )
const ( // Default length of the fixed header for v4 events. BinlogFixedHeaderLen = 19 // The offset from 0 where the type is stored as 1 byte. BinlogEventTypeOffset = 4 // Offset from 0 where the 4 byte length is stored. BinlogEventLenOffset = 9 // Byte length of the checksum suffix when the CRC32 algorithm is used. BinlogCRC32ChecksumLen = 4 )
const ( TransactionPayloadCompressionZstd = 0 TransactionPayloadCompressionNone = 255 )
Compression algorithms that are supported (only zstd today in MySQL 8.0): https://dev.mysql.com/doc/refman/8.0/en/binary-log-transaction-compression.html
const ( // MaxPacketSize is the maximum payload length of a packet // the server supports. MaxPacketSize = (1 << 24) - 1 // https://dev.mysql.com/doc/refman/en/identifier-length.html MaxIdentifierLength = 64 )
const ( // MysqlNativePassword uses a salt and transmits a hash on the wire. MysqlNativePassword = AuthMethodDescription("mysql_native_password") // MysqlClearPassword transmits the password in the clear. MysqlClearPassword = AuthMethodDescription("mysql_clear_password") // CachingSha2Password uses a salt and transmits a SHA256 hash on the wire. CachingSha2Password = AuthMethodDescription("caching_sha2_password") // MysqlDialog uses the dialog plugin on the client side. // It transmits data in the clear. MysqlDialog = AuthMethodDescription("dialog") )
Supported auth forms.
const ( // CapabilityClientLongPassword is CLIENT_LONG_PASSWORD. // New more secure passwords. Assumed to be set since 4.1.1. // We do not check this anywhere. CapabilityClientLongPassword = 1 // CapabilityClientFoundRows is CLIENT_FOUND_ROWS. CapabilityClientFoundRows = 1 << 1 // CapabilityClientLongFlag is CLIENT_LONG_FLAG. // Longer flags in Protocol::ColumnDefinition320. // Set it everywhere, not used, as we use Protocol::ColumnDefinition41. CapabilityClientLongFlag = 1 << 2 // CapabilityClientConnectWithDB is CLIENT_CONNECT_WITH_DB. // One can specify db on connect. CapabilityClientConnectWithDB = 1 << 3 // CapabilityClientProtocol41 is CLIENT_PROTOCOL_41. // New 4.1 protocol. Enforced everywhere. CapabilityClientProtocol41 = 1 << 9 // CapabilityClientSSL is CLIENT_SSL. // Switch to SSL after handshake. CapabilityClientSSL = 1 << 11 // CapabilityClientTransactions is CLIENT_TRANSACTIONS. // Can send status flags in EOF_Packet. // This flag is optional in 3.23, but always set by the server since 4.0. // We just do it all the time. CapabilityClientTransactions = 1 << 13 // CapabilityClientSecureConnection is CLIENT_SECURE_CONNECTION. // New 4.1 authentication. Always set, expected, never checked. CapabilityClientSecureConnection = 1 << 15 // CapabilityClientMultiStatements is CLIENT_MULTI_STATEMENTS // Can handle multiple statements per COM_QUERY and COM_STMT_PREPARE. CapabilityClientMultiStatements = 1 << 16 // CapabilityClientMultiResults is CLIENT_MULTI_RESULTS // Can send multiple resultsets for COM_QUERY. CapabilityClientMultiResults = 1 << 17 // CapabilityClientPluginAuth is CLIENT_PLUGIN_AUTH. // Client supports plugin authentication. CapabilityClientPluginAuth = 1 << 19 // CapabilityClientConnAttr is CLIENT_CONNECT_ATTRS // Permits connection attributes in Protocol::HandshakeResponse41. CapabilityClientConnAttr = 1 << 20 // CapabilityClientPluginAuthLenencClientData is CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA CapabilityClientPluginAuthLenencClientData = 1 << 21 // CLIENT_SESSION_TRACK 1 << 23 // Can set ServerSessionStateChanged in the Status Flags // and send session-state change data after a OK packet. // Not yet supported. CapabilityClientSessionTrack = 1 << 23 // CapabilityClientDeprecateEOF is CLIENT_DEPRECATE_EOF // Expects an OK (instead of EOF) after the resultset rows of a Text Resultset. CapabilityClientDeprecateEOF = 1 << 24 )
Capability flags. Originally found in include/mysql/mysql_com.h
const ( // a transaction is active ServerStatusInTrans uint16 = 0x0001 NoServerStatusInTrans uint16 = 0xFFFE // auto-commit is enabled ServerStatusAutocommit uint16 = 0x0002 NoServerStatusAutocommit uint16 = 0xFFFD ServerMoreResultsExists uint16 = 0x0008 ServerStatusNoGoodIndexUsed uint16 = 0x0010 ServerStatusNoIndexUsed uint16 = 0x0020 // Used by Binary Protocol Resultset to signal that COM_STMT_FETCH must be used to fetch the row-data. ServerStatusCursorExists uint16 = 0x0040 ServerStatusLastRowSent uint16 = 0x0080 ServerStatusDbDropped uint16 = 0x0100 ServerStatusNoBackslashEscapes uint16 = 0x0200 ServerStatusMetadataChanged uint16 = 0x0400 ServerQueryWasSlow uint16 = 0x0800 ServerPsOutParams uint16 = 0x1000 // in a read-only transaction ServerStatusInTransReadonly uint16 = 0x2000 // connection state information has changed ServerSessionStateChanged uint16 = 0x4000 )
Status flags. They are returned by the server in a few cases. Originally found in include/mysql/mysql_com.h See http://dev.mysql.com/doc/internals/en/status-flags.html
const ( // one or more system variables changed. SessionTrackSystemVariables uint8 = 0x00 // schema changed. SessionTrackSchema uint8 = 0x01 // "track state change" changed. SessionTrackStateChange uint8 = 0x02 // "track GTIDs" changed. SessionTrackGtids uint8 = 0x03 )
State Change Information
const ( // ComQuit is COM_QUIT. ComQuit = 0x01 // ComInitDB is COM_INIT_DB. ComInitDB = 0x02 // ComQuery is COM_QUERY. ComQuery = 0x03 // ComFieldList is COM_Field_List. ComFieldList = 0x04 // ComPing is COM_PING. ComPing = 0x0e // ComBinlogDump is COM_BINLOG_DUMP. ComBinlogDump = 0x12 // ComSemiSyncAck is SEMI_SYNC_ACK. ComSemiSyncAck = 0xef // ComPrepare is COM_PREPARE. ComPrepare = 0x16 // ComStmtExecute is COM_STMT_EXECUTE. ComStmtExecute = 0x17 // ComStmtSendLongData is COM_STMT_SEND_LONG_DATA ComStmtSendLongData = 0x18 // ComStmtClose is COM_STMT_CLOSE. ComStmtClose = 0x19 // ComStmtReset is COM_STMT_RESET ComStmtReset = 0x1a //ComStmtFetch is COM_STMT_FETCH ComStmtFetch = 0x1c // ComSetOption is COM_SET_OPTION ComSetOption = 0x1b // ComResetConnection is COM_RESET_CONNECTION ComResetConnection = 0x1f // ComBinlogDumpGTID is COM_BINLOG_DUMP_GTID. ComBinlogDumpGTID = 0x1e // ComRegisterReplica is COM_REGISTER_SLAVE // https://dev.mysql.com/doc/internals/en/com-register-slave.html ComRegisterReplica = 0x15 // OKPacket is the header of the OK packet. OKPacket = 0x00 // EOFPacket is the header of the EOF packet. EOFPacket = 0xfe // ErrPacket is the header of the error packet. ErrPacket = 0xff // NullValue is the encoded value of NULL. NullValue = 0xfb )
Packet types. Originally found in include/mysql/mysql_com.h
const ( // AuthMoreDataPacket is sent when server requires more data to authenticate AuthMoreDataPacket = 0x01 // CachingSha2FastAuth is sent before OKPacket when server authenticates using cache CachingSha2FastAuth = 0x03 // CachingSha2FullAuth is sent when server requests un-scrambled password to authenticate CachingSha2FullAuth = 0x04 // AuthSwitchRequestPacket is used to switch auth method. AuthSwitchRequestPacket = 0xfe )
Auth packet types
const ( // IntVarInvalidInt is INVALID_INT_EVENT IntVarInvalidInt = 0 // IntVarLastInsertID is LAST_INSERT_ID_EVENT IntVarLastInsertID = 1 // IntVarInsertID is INSERT_ID_EVENT IntVarInsertID = 2 )
Constants for the type of an INTVAR_EVENT.
const ( // BinlogChecksumAlgOff indicates that checksums are supported but off. BinlogChecksumAlgOff = 0 // BinlogChecksumAlgCRC32 indicates that CRC32 checksums are used. BinlogChecksumAlgCRC32 = 1 // BinlogChecksumAlgUndef indicates that checksums are not supported. BinlogChecksumAlgUndef = 255 )
Constants about the type of checksum in a packet. These constants are common between MariaDB 10.0 and MySQL 5.6.
const ( // QFlags2Code is Q_FLAGS2_CODE QFlags2Code = 0 // QSQLModeCode is Q_SQL_MODE_CODE QSQLModeCode = 1 // QCatalog is Q_CATALOG QCatalog = 2 // QAutoIncrement is Q_AUTO_INCREMENT QAutoIncrement = 3 // QCharsetCode is Q_CHARSET_CODE QCharsetCode = 4 // QTimeZoneCode is Q_TIME_ZONE_CODE QTimeZoneCode = 5 // QCatalogNZCode is Q_CATALOG_NZ_CODE QCatalogNZCode = 6 )
These constants describe the type of status variables in q Query packet.
const ( // BaseShowPrimary is the base query for fetching primary key info. BaseShowPrimary = `` /* 203-byte string literal not displayed */ // ShowRowsRead is the query used to find the number of rows read. ShowRowsRead = "show status like 'Innodb_rows_read'" // GetColumnNamesQueryPatternForTable is used for mocking queries in unit tests GetColumnNamesQueryPatternForTable = `SELECT COLUMN_NAME.*TABLE_NAME.*%s.*` )
const CapabilityFlags uint32 = CapabilityClientLongPassword | CapabilityClientLongFlag | CapabilityClientProtocol41 | CapabilityClientTransactions | CapabilityClientSecureConnection | CapabilityClientMultiStatements | CapabilityClientMultiResults | CapabilityClientPluginAuth | CapabilityClientPluginAuthLenencClientData
CapabilityFlags are client capability flag sent to mysql on connect
const CapabilityFlagsSsl = CapabilityFlags | CapabilityClientSSL
CapabilityFlagsSsl signals that we can handle SSL as well
const (
DefaultFlushDelay = 100 * time.Millisecond
)
const ( // The directory used for redo logs within innodb_log_group_home_dir // in MySQL 8.0.30 and later. // You would check to see if this is relevant using the Flavor's // capability interface to check for DynamicRedoLogCapacityFlavorCapability. DynamicRedoLogSubdir = "#innodb_redo" )
const (
FlagLogEventArtificial = 0x20
)
const GRFlavorID = "MysqlGR"
GRFlavorID is the string identifier for the MysqlGR flavor.
const TablesWithSize56 = `` /* 293-byte string literal not displayed */
TablesWithSize56 is a query to select table along with size for mysql 5.6
const TablesWithSize57 = `` /* 679-byte string literal not displayed */
TablesWithSize57 is a query to select table along with size for mysql 5.7.
It's a little weird, because the JOIN predicate only works if the table and databases do not contain weird characters. If the join does not return any data, we fall back to the same fields as used in the mysql 5.6 query.
We join with a subquery that materializes the data from `information_schema.innodb_sys_tablespaces` early for performance reasons. This effectively causes only a single read of `information_schema.innodb_sys_tablespaces` per query.
const TablesWithSize80 = `` /* 480-byte string literal not displayed */
TablesWithSize80 is a query to select table along with size for mysql 8.0
Note the following:
- We use a single query to fetch both partitioned and non-partitioned tables. This is because accessing `information_schema.innodb_tablespaces` is expensive on servers with many tablespaces, and every query that loads the table needs to perform full table scans on it. Doing a single table scan is more efficient than doing more than one.
- We utilize `INFORMATION_SCHEMA`.`TABLES`.`CREATE_OPTIONS` column to do early pruning before the JOIN.
- `TABLES`.`TABLE_NAME` has `utf8mb4_0900_ai_ci` collation. `INNODB_TABLESPACES`.`NAME` has `utf8mb3_general_ci`. We normalize the collation to get better query performance (we force the casting at the time of our choosing)
Variables ¶
var ( // ErrNotReplica means there is no replication status. // Returned by ShowReplicationStatus(). ErrNotReplica = sqlerror.NewSQLError(sqlerror.ERNotReplica, sqlerror.SSUnknownSQLState, "no replication status") // ErrNoPrimaryStatus means no status was returned by ShowPrimaryStatus(). ErrNoPrimaryStatus = errors.New("no master status") )
var BaseShowTablesFields = []*querypb.Field{{ Name: "t.table_name", Type: querypb.Type_VARCHAR, Table: "tables", OrgTable: "TABLES", Database: "information_schema", OrgName: "TABLE_NAME", ColumnLength: 192, Charset: uint32(collations.SystemCollation.Collation), Flags: uint32(querypb.MySqlFlag_NOT_NULL_FLAG), }, { Name: "t.table_type", Type: querypb.Type_VARCHAR, Table: "tables", OrgTable: "TABLES", Database: "information_schema", OrgName: "TABLE_TYPE", ColumnLength: 192, Charset: uint32(collations.SystemCollation.Collation), Flags: uint32(querypb.MySqlFlag_NOT_NULL_FLAG), }, { Name: "unix_timestamp(t.create_time)", Type: querypb.Type_INT64, ColumnLength: 11, Charset: collations.CollationBinaryID, Flags: uint32(querypb.MySqlFlag_BINARY_FLAG | querypb.MySqlFlag_NUM_FLAG), }, { Name: "t.table_comment", Type: querypb.Type_VARCHAR, Table: "tables", OrgTable: "TABLES", Database: "information_schema", OrgName: "TABLE_COMMENT", ColumnLength: 6144, Charset: uint32(collations.SystemCollation.Collation), Flags: uint32(querypb.MySqlFlag_NOT_NULL_FLAG), }, { Name: "i.file_size", Type: querypb.Type_INT64, ColumnLength: 11, Charset: collations.CollationBinaryID, Flags: uint32(querypb.MySqlFlag_BINARY_FLAG | querypb.MySqlFlag_NUM_FLAG), }, { Name: "i.allocated_size", Type: querypb.Type_INT64, ColumnLength: 11, Charset: collations.CollationBinaryID, Flags: uint32(querypb.MySqlFlag_BINARY_FLAG | querypb.MySqlFlag_NUM_FLAG), }}
BaseShowTablesFields contains the fields returned by a BaseShowTables or a BaseShowTablesForTable command. They are validated by the testBaseShowTables test.
var ( // BinglogMagicNumber is 4-byte number at the beginning of every binary log BinglogMagicNumber = []byte{0xfe, 0x62, 0x69, 0x6e} )
var ErrNoGroupStatus = errors.New("no group status")
ErrNoGroupStatus means no status for group replication.
var ( // IntVarNames maps a InVar type to the variable name it represents. IntVarNames = map[byte]string{ IntVarLastInsertID: "LAST_INSERT_ID", IntVarInsertID: "INSERT_ID", } )
Name of the variable represented by an IntVar.
var ShowPrimaryFields = []*querypb.Field{{ Name: "table_name", Type: sqltypes.VarChar, }, { Name: "column_name", Type: sqltypes.VarChar, }}
ShowPrimaryFields contains the fields for a BaseShowPrimary.
var TransactionPayloadCompressionTypes = map[uint64]string{ TransactionPayloadCompressionZstd: "ZSTD", TransactionPayloadCompressionNone: "NONE", }
Functions ¶
func BaseShowTablesRow ¶
BaseShowTablesRow returns the fields from a BaseShowTables or BaseShowTablesForTable command.
func DecodeMysqlNativePasswordHex ¶ added in v0.12.0
DecodeMysqlNativePasswordHex decodes the standard format used by MySQL for 4.1 style password hashes. It drops the optionally leading * before decoding the rest as a hex encoded string.
func EncryptPasswordWithPublicKey ¶ added in v0.10.0
EncryptPasswordWithPublicKey obfuscates the password and encrypts it with server's public key as required by caching_sha2_password plugin for "full" authentication
func ExecuteFetchMap ¶
ExecuteFetchMap returns a map from column names to cell data for a query that should return exactly 1 row.
func FlagsForColumn ¶ added in v0.17.2
func FlagsForColumn(t sqltypes.Type, col collations.ID) uint32
func GetCharset ¶
func GetCharset(conn *Conn) (*binlogdatapb.Charset, error)
GetCharset returns the current numerical values of the per-session character set variables.
func GetFlavor ¶ added in v0.14.0
func GetFlavor(serverVersion string, flavorFunc func() flavor) (f flavor, capableOf capabilities.CapableOf, canonicalVersion string)
GetFlavor fills in c.Flavor. If the params specify the flavor, that is used. Otherwise, we auto-detect.
This is the same logic as the ConnectorJ java client. We try to recognize MariaDB as much as we can, but default to MySQL.
MariaDB note: the server version returned here might look like: 5.5.5-10.0.21-MariaDB-... If that is the case, we are removing the 5.5.5- prefix. Note on such servers, 'select version()' would return 10.0.21-MariaDB-... as well (not matching what c.ServerVersion is, but matching after we remove the prefix).
func InitAuthServerClientCert ¶
func InitAuthServerClientCert(clientcertAuthMethod string)
InitAuthServerClientCert is public so it can be called from plugin_auth_clientcert.go (go/cmd/vtgate)
func InitAuthServerStatic ¶
func InitAuthServerStatic(mysqlAuthServerStaticFile, mysqlAuthServerStaticString string, mysqlAuthServerStaticReloadInterval time.Duration)
InitAuthServerStatic Handles initializing the AuthServerStatic if necessary.
func IsNum ¶
IsNum returns true if a MySQL type is a numeric value. It is the same as IS_NUM defined in mysql.h.
func MatchSourceHost ¶ added in v0.12.0
MatchSourceHost validates host entry in auth configuration
func ParseConfig ¶ added in v0.12.0
func ParseConfig(jsonBytes []byte, config *map[string][]*AuthServerStaticEntry) error
ParseConfig takes a JSON MySQL static config and converts to a validated map
func ParseErrorPacket ¶
ParseErrorPacket parses the error packet and returns a SQLError.
func RegisterAuthServer ¶ added in v0.12.0
func RegisterAuthServer(name string, authServer AuthServer)
RegisterAuthServer registers an implementations of AuthServer.
func RegisterAuthServerStaticFromParams ¶
RegisterAuthServerStaticFromParams creates and registers a new AuthServerStatic, loaded for a JSON file or string. If file is set, it uses file. Otherwise, load the string. It log.Exits out in case of error.
func ScrambleCachingSha2Password ¶ added in v0.10.0
ScrambleCachingSha2Password computes the hash of the password using SHA256 as required by caching_sha2_password plugin for "fast" authentication
func ScrambleMysqlNativePassword ¶ added in v0.10.0
ScrambleMysqlNativePassword computes the hash of the password using 4.1+ method.
This can be used for example inside a `mysql_native_password` plugin implementation if the backend storage implements storage of plain text passwords.
func ServerVersionCapableOf ¶ added in v0.19.0
func ServerVersionCapableOf(serverVersion string) (capableOf capabilities.CapableOf)
ServerVersionCapableOf is a convenience function that returns a CapableOf function given a server version. It is a shortcut for GetFlavor(serverVersion, nil).
func SetCharset ¶
func SetCharset(conn *Conn, cs *binlogdatapb.Charset) error
SetCharset changes the per-session character set variables.
func ShowPrimaryRow ¶
ShowPrimaryRow returns a row for a primary key column.
func VerifyHashedCachingSha2Password ¶ added in v0.12.0
VerifyHashedCachingSha2Password verifies a client reply against a stored hash.
This can be used for example inside a `caching_sha2_password` plugin implementation if the cache storage uses password keys with SHA256(SHA256(password)).
All values here are non encoded byte slices, so if you store for example the double SHA256 of the password as hex encoded characters, you need to decode that first.
func VerifyHashedMysqlNativePassword ¶ added in v0.12.0
VerifyHashedMysqlNativePassword verifies a client reply against a stored hash.
This can be used for example inside a `mysql_native_password` plugin implementation if the backend storage where the stored password is a SHA1(SHA1(password)).
All values here are non encoded byte slices, so if you store for example the double SHA1 of the password as hex encoded characters, you need to decode that first. See DecodeMysqlNativePasswordHex for a decoding helper for the standard encoding format of this hash used by MySQL.
Types ¶
type AuthMethod ¶ added in v0.12.0
type AuthMethod interface { // Name returns the auth method description for this implementation. // This is the name that is sent as the auth plugin name during the // Mysql authentication protocol handshake. Name() AuthMethodDescription // HandleUser verifies if the current auth method can authenticate // the given user with the current auth method. This can be useful // for example if you only have a plain text of hashed password // for specific users and not all users and auth method support // depends on what you have. HandleUser(conn *Conn, user string) bool // AllowClearTextWithoutTLS identifies if an auth method is allowed // on a plain text connection. This check is only enforced // if the listener has AllowClearTextWithoutTLS() disabled. AllowClearTextWithoutTLS() bool // AuthPluginData generates the information for the auth plugin. // This is included in for example the auth switch request. This // is auth plugin specific and opaque to the Mysql handshake // protocol. AuthPluginData() ([]byte, error) // HandleAuthPluginData handles the returned auth plugin data from // the client. The original data the server sent is also included // which can include things like the salt for `mysql_native_password`. // // The remote address is provided for plugins that also want to // do additional checks like IP based restrictions. HandleAuthPluginData(conn *Conn, user string, serverAuthPluginData []byte, clientAuthPluginData []byte, remoteAddr net.Addr) (Getter, error) }
AuthMethod interface for concrete auth method implementations. When building an auth server, you usually don't implement these yourself but the helper methods to build AuthMethod instances should be used.
func NewMysqlClearAuthMethod ¶ added in v0.12.0
func NewMysqlClearAuthMethod(layer PlainTextStorage, validator UserValidator) AuthMethod
NewMysqlClearAuthMethod will create a new AuthMethod that implements the `mysql_clear_password` handshake. The caller will need to provide a storage object for plain text passwords and validator that will be called during the handshake phase.
func NewMysqlDialogAuthMethod ¶ added in v0.12.0
func NewMysqlDialogAuthMethod(layer PlainTextStorage, validator UserValidator, msg string) AuthMethod
NewMysqlDialogAuthMethod will create a new AuthMethod that implements the `dialog` handshake. The caller will need to provide a storage object for plain text passwords and validator that will be called during the handshake phase. The message given will be sent as part of the dialog. If the empty string is provided, the default message of "Enter password: " will be used.
func NewMysqlNativeAuthMethod ¶ added in v0.12.0
func NewMysqlNativeAuthMethod(layer HashStorage, validator UserValidator) AuthMethod
NewMysqlNativeAuthMethod will create a new AuthMethod that implements the `mysql_native_password` handshake. The caller will need to provide a storage object and validator that will be called during the handshake phase.
func NewSha2CachingAuthMethod ¶ added in v0.12.0
func NewSha2CachingAuthMethod(layer1 CachingStorage, layer2 PlainTextStorage, validator UserValidator) AuthMethod
NewSha2CachingAuthMethod will create a new AuthMethod that implements the `caching_sha2_password` handshake. The caller will need to provide a cache object for the fast auth path and a plain text storage object that will be called if the return of the first layer indicates the full auth dance is needed.
Right now we only support caching_sha2_password over TLS or a Unix socket.
If TLS is not enabled, the client needs to encrypt it with the public key of the server. In that case, Vitess is already configured with a certificate anyway, so we recommend to use TLS if you want to use caching_sha2_password in that case instead of allowing the plain text fallback path here.
This might change in the future if there's a good argument and implementation for allowing the plain text path here as well.
type AuthMethodDescription ¶ added in v0.12.0
type AuthMethodDescription string
AuthMethodDescription is the type for different supported and implemented authentication methods.
type AuthServer ¶
type AuthServer interface { // AuthMethods returns a list of auth methods that are part of this // interface. Building an authentication server usually means // creating AuthMethod instances with the known helpers for the // currently supported AuthMethod implementations. // // When a client connects, the server checks the list of auth methods // available. If an auth method for the requested auth mechanism by the // client is available, it will be used immediately. // // If there is no overlap between the provided auth methods and // the one the client requests, the server will send back an // auth switch request using the first provided AuthMethod in this list. AuthMethods() []AuthMethod // DefaultAuthMethodDescription returns the auth method that the auth server // sends during the initial server handshake. This needs to be either // `mysql_native_password` or `caching_sha2_password` as those are the only // supported auth methods during the initial handshake. // // It's not needed to also support those methods in the AuthMethods(), // in fact, if you want to only support for example clear text passwords, // you must still return `mysql_native_password` or `caching_sha2_password` // here and the auth switch protocol will be used to switch to clear text. DefaultAuthMethodDescription() AuthMethodDescription }
AuthServer is the interface that servers must implement to validate users and passwords. It needs to be able to return a list of AuthMethod interfaces which implement the supported auth methods for the server.
func GetAuthServer ¶
func GetAuthServer(name string) AuthServer
GetAuthServer returns an AuthServer by name, or log.Exitf.
type AuthServerClientCert ¶
type AuthServerClientCert struct { Method AuthMethodDescription // contains filtered or unexported fields }
AuthServerClientCert implements AuthServer which enforces client side certificates
func (*AuthServerClientCert) AuthMethods ¶ added in v0.12.0
func (asl *AuthServerClientCert) AuthMethods() []AuthMethod
AuthMethods returns the implement auth methods for the client certificate authentication setup.
func (*AuthServerClientCert) DefaultAuthMethodDescription ¶ added in v0.12.0
func (asl *AuthServerClientCert) DefaultAuthMethodDescription() AuthMethodDescription
DefaultAuthMethodDescription returns always MysqlNativePassword for the client certificate authentication setup.
func (*AuthServerClientCert) HandleUser ¶ added in v0.12.0
func (asl *AuthServerClientCert) HandleUser(user string) bool
HandleUser is part of the UserValidator interface. We handle any user here since we don't check up front.
func (*AuthServerClientCert) UserEntryWithPassword ¶ added in v0.12.0
func (asl *AuthServerClientCert) UserEntryWithPassword(conn *Conn, user string, password string, remoteAddr net.Addr) (Getter, error)
UserEntryWithPassword is part of the PlaintextStorage interface
type AuthServerNone ¶
type AuthServerNone struct {
// contains filtered or unexported fields
}
AuthServerNone takes all comers. It's meant to be used for testing and prototyping. With this config, you can connect to a local vtgate using the following command line: 'mysql -P port -h ::'. It only uses MysqlNativePassword method.
func NewAuthServerNone ¶ added in v0.12.0
func NewAuthServerNone() *AuthServerNone
NewAuthServerNone returns an empty auth server. Always accepts all clients.
func (*AuthServerNone) AuthMethods ¶ added in v0.12.0
func (a *AuthServerNone) AuthMethods() []AuthMethod
AuthMethods returns the list of registered auth methods implemented by this auth server.
func (*AuthServerNone) DefaultAuthMethodDescription ¶ added in v0.12.0
func (a *AuthServerNone) DefaultAuthMethodDescription() AuthMethodDescription
DefaultAuthMethodDescription returns MysqlNativePassword as the default authentication method for the auth server implementation.
func (*AuthServerNone) HandleUser ¶ added in v0.12.0
func (a *AuthServerNone) HandleUser(user string) bool
HandleUser validates if this user can use this auth method
func (*AuthServerNone) UserEntryWithHash ¶ added in v0.12.0
func (a *AuthServerNone) UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error)
UserEntryWithHash validates the user if it exists and returns the information. Always accepts any user.
type AuthServerStatic ¶
type AuthServerStatic struct {
// contains filtered or unexported fields
}
AuthServerStatic implements AuthServer using a static configuration.
func NewAuthServerStatic ¶
func NewAuthServerStatic(file, jsonConfig string, reloadInterval time.Duration) *AuthServerStatic
NewAuthServerStatic returns a new empty AuthServerStatic.
func NewAuthServerStaticWithAuthMethodDescription ¶ added in v0.12.0
func NewAuthServerStaticWithAuthMethodDescription(file, jsonConfig string, reloadInterval time.Duration, authMethodDescription AuthMethodDescription) *AuthServerStatic
NewAuthServerStaticWithAuthMethodDescription returns a new empty AuthServerStatic but with support for a different auth method. Mostly used for testing purposes.
func (*AuthServerStatic) AuthMethods ¶ added in v0.12.0
func (a *AuthServerStatic) AuthMethods() []AuthMethod
AuthMethods returns the AuthMethod instances this auth server can handle.
func (*AuthServerStatic) DefaultAuthMethodDescription ¶ added in v0.12.0
func (a *AuthServerStatic) DefaultAuthMethodDescription() AuthMethodDescription
DefaultAuthMethodDescription returns the default auth method in the handshake which is MysqlNativePassword for this auth server.
func (*AuthServerStatic) HandleUser ¶ added in v0.12.0
func (a *AuthServerStatic) HandleUser(user string) bool
HandleUser is part of the Validator interface. We handle any user here since we don't check up front.
func (*AuthServerStatic) UserEntryWithCacheHash ¶ added in v0.12.0
func (a *AuthServerStatic) UserEntryWithCacheHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, CacheState, error)
UserEntryWithCacheHash implements password lookup based on a caching_sha2_password hash that is negotiated with the client.
func (*AuthServerStatic) UserEntryWithHash ¶ added in v0.12.0
func (a *AuthServerStatic) UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error)
UserEntryWithHash implements password lookup based on a mysql_native_password hash that is negotiated with the client.
func (*AuthServerStatic) UserEntryWithPassword ¶ added in v0.12.0
func (a *AuthServerStatic) UserEntryWithPassword(conn *Conn, user string, password string, remoteAddr net.Addr) (Getter, error)
UserEntryWithPassword implements password lookup based on a plain text password that is negotiated with the client.
type AuthServerStaticEntry ¶
type AuthServerStaticEntry struct { // MysqlNativePassword is generated by password hashing methods in MySQL. // These changes are illustrated by changes in the result from the PASSWORD() function // that computes password hash values and in the structure of the user table where passwords are stored. // mysql> SELECT PASSWORD('mypass'); // +-------------------------------------------+ // | PASSWORD('mypass') | // +-------------------------------------------+ // | *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4 | // +-------------------------------------------+ // MysqlNativePassword's format looks like "*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4", it store a hashing value. // Use MysqlNativePassword in auth config, maybe more secure. After all, it is cryptographic storage. MysqlNativePassword string Password string UserData string SourceHost string Groups []string }
AuthServerStaticEntry stores the values for a given user.
type BinlogEvent ¶
type BinlogEvent interface { // IsValid returns true if the underlying data buffer contains a valid // event. This should be called first on any BinlogEvent, and other // methods should only be called if this one returns true. This ensures // you won't get panics due to bounds checking on the byte array. IsValid() bool // General protocol events. NextPosition() uint32 // IsFormatDescription returns true if this is a // FORMAT_DESCRIPTION_EVENT. Do not call StripChecksum before // calling Format (Format returns the BinlogFormat anyway, // required for calling StripChecksum). IsFormatDescription() bool // IsQuery returns true if this is a QUERY_EVENT, which encompasses // all SQL statements. IsQuery() bool // IsXID returns true if this is an XID_EVENT, which is an alternate // form of COMMIT. IsXID() bool // IsStop returns true if this is a STOP_EVENT. IsStop() bool // IsGTID returns true if this is a GTID_EVENT. IsGTID() bool // IsRotate returns true if this is a ROTATE_EVENT. IsRotate() bool // IsIntVar returns true if this is an INTVAR_EVENT. IsIntVar() bool // IsRand returns true if this is a RAND_EVENT. IsRand() bool // IsPreviousGTIDs returns true if this event is a PREVIOUS_GTIDS_EVENT. IsPreviousGTIDs() bool // IsHeartbeat returns true if this event is a HEARTBEAT_EVENT. IsHeartbeat() bool // IsSemiSyncAckRequested returns true if the source requests a semi-sync ack for this event IsSemiSyncAckRequested() bool // IsTableMap returns true if this is a TABLE_MAP_EVENT. IsTableMap() bool // IsWriteRows returns true if this is a WRITE_ROWS_EVENT. IsWriteRows() bool // IsUpdateRows returns true if this is a UPDATE_ROWS_EVENT. IsUpdateRows() bool // IsDeleteRows returns true if this is a DELETE_ROWS_EVENT. IsDeleteRows() bool // Timestamp returns the timestamp from the event header. Timestamp() uint32 // Format returns a BinlogFormat struct based on the event data. // This is only valid if IsFormatDescription() returns true. Format() (BinlogFormat, error) // GTID returns the GTID from the event, and if this event // also serves as a BEGIN statement. // This is only valid if IsGTID() returns true. GTID(BinlogFormat) (replication.GTID, bool, error) // Query returns a Query struct representing data from a QUERY_EVENT. // This is only valid if IsQuery() returns true. Query(BinlogFormat) (Query, error) // IntVar returns the type and value of the variable for an INTVAR_EVENT. // This is only valid if IsIntVar() returns true. IntVar(BinlogFormat) (byte, uint64, error) // Rand returns the two seed values for a RAND_EVENT. // This is only valid if IsRand() returns true. Rand(BinlogFormat) (uint64, uint64, error) // PreviousGTIDs returns the Position from the event. // This is only valid if IsPreviousGTIDs() returns true. PreviousGTIDs(BinlogFormat) (replication.Position, error) // TableID returns the table ID for a TableMap, UpdateRows, // WriteRows or DeleteRows event. TableID(BinlogFormat) uint64 // TableMap returns a TableMap struct representing data from a // TABLE_MAP_EVENT. This is only valid if IsTableMapEvent() returns // true. TableMap(BinlogFormat) (*TableMap, error) // Rows returns a Rows struct representing data from a // {WRITE,UPDATE,DELETE}_ROWS_EVENT. This is only valid if // IsWriteRows(), IsUpdateRows(), or IsDeleteRows() returns // true. Rows(BinlogFormat, *TableMap) (Rows, error) // TransactionPayload returns a list of BinlogEvents contained // within the compressed transaction. TransactionPayload(BinlogFormat) ([]BinlogEvent, error) // NextLogFile returns the name of the next binary log file & pos. // This is only valid if IsRotate() returns true NextLogFile(BinlogFormat) (string, uint64, error) // StripChecksum returns the checksum and a modified event with the // checksum stripped off, if any. If there is no checksum, it returns // the same event and a nil checksum. StripChecksum(BinlogFormat) (ev BinlogEvent, checksum []byte, err error) // IsPseudo is for custom implementations of GTID. IsPseudo() bool // IsTransactionPayload returns true if a compressed transaction // payload event is found (binlog_transaction_compression=ON). IsTransactionPayload() bool // Bytes returns the binary representation of the event Bytes() []byte }
BinlogEvent represents a single event from a raw MySQL binlog dump stream. The implementation is provided by each supported flavor in go/vt/mysqlctl.
binlog.Streamer receives these events through a mysqlctl.BinlogConnection and processes them, grouping statements into BinlogTransactions as appropriate.
Methods that only access header fields can't fail as long as IsValid() returns true, so they have a single return value. Methods that might fail even when IsValid() is true return an error value.
Methods that require information from the initial FORMAT_DESCRIPTION_EVENT will have a BinlogFormat parameter.
A BinlogEvent should never be sent over the wire. UpdateStream service will send BinlogTransactions from these events.
func NewDeleteRowsEvent ¶
func NewDeleteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent
NewDeleteRowsEvent returns an DeleteRows event. Uses v2.
func NewFakeRotateEvent ¶ added in v0.16.0
func NewFakeRotateEvent(f BinlogFormat, s *FakeBinlogStream, filename string) BinlogEvent
func NewFormatDescriptionEvent ¶
func NewFormatDescriptionEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
NewFormatDescriptionEvent creates a new FormatDescriptionEvent based on the provided BinlogFormat. It uses a mysql56BinlogEvent but could use a MariaDB one.
func NewHeartbeatEvent ¶ added in v0.16.0
func NewHeartbeatEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
NewHeartbeatEvent returns a HeartbeatEvent. see https://dev.mysql.com/doc/internals/en/heartbeat-event.html
func NewHeartbeatEventWithLogFile ¶ added in v0.16.0
func NewHeartbeatEventWithLogFile(f BinlogFormat, s *FakeBinlogStream, filename string) BinlogEvent
NewHeartbeatEvent returns a HeartbeatEvent. see https://dev.mysql.com/doc/internals/en/heartbeat-event.html
func NewIntVarEvent ¶
func NewIntVarEvent(f BinlogFormat, s *FakeBinlogStream, typ byte, value uint64) BinlogEvent
NewIntVarEvent returns an IntVar event.
func NewInvalidEvent ¶
func NewInvalidEvent() BinlogEvent
NewInvalidEvent returns an invalid event (its size is <19).
func NewInvalidFormatDescriptionEvent ¶
func NewInvalidFormatDescriptionEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
NewInvalidFormatDescriptionEvent returns an invalid FormatDescriptionEvent. The binlog version is set to 3. It IsValid() though.
func NewInvalidQueryEvent ¶
func NewInvalidQueryEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
NewInvalidQueryEvent returns an invalid QueryEvent. IsValid is however true. sqlPos is out of bounds.
func NewMariaDBGTIDEvent ¶
func NewMariaDBGTIDEvent(f BinlogFormat, s *FakeBinlogStream, gtid replication.MariadbGTID, hasBegin bool) BinlogEvent
NewMariaDBGTIDEvent returns a MariaDB specific GTID event. It ignores the Server in the gtid, instead uses the FakeBinlogStream.ServerID.
func NewMariadbBinlogEvent ¶
func NewMariadbBinlogEvent(buf []byte) BinlogEvent
NewMariadbBinlogEvent creates a BinlogEvent instance from given byte array
func NewMariadbBinlogEventWithSemiSyncInfo ¶ added in v0.14.0
func NewMariadbBinlogEventWithSemiSyncInfo(buf []byte, semiSyncAckRequested bool) BinlogEvent
NewMariadbBinlogEventWithSemiSyncInfo creates a BinlogEvent instance from given byte array
func NewMysql56BinlogEvent ¶
func NewMysql56BinlogEvent(buf []byte) BinlogEvent
NewMysql56BinlogEvent creates a BinlogEvent from given byte array
func NewMysql56BinlogEventWithSemiSyncInfo ¶ added in v0.14.0
func NewMysql56BinlogEventWithSemiSyncInfo(buf []byte, semiSyncAckRequested bool) BinlogEvent
NewMysql56BinlogEventWithSemiSyncInfo creates a BinlogEvent from given byte array
func NewQueryEvent ¶
func NewQueryEvent(f BinlogFormat, s *FakeBinlogStream, q Query) BinlogEvent
NewQueryEvent makes up a QueryEvent based on the Query structure.
func NewRotateEvent ¶
func NewRotateEvent(f BinlogFormat, s *FakeBinlogStream, position uint64, filename string) BinlogEvent
NewRotateEvent returns a RotateEvent. The timestamp of such an event should be zero, so we patch it in.
func NewTableMapEvent ¶
func NewTableMapEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, tm *TableMap) BinlogEvent
NewTableMapEvent returns a TableMap event. Only works with post_header_length=8.
func NewUpdateRowsEvent ¶
func NewUpdateRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent
NewUpdateRowsEvent returns an UpdateRows event. Uses v2.
func NewWriteRowsEvent ¶
func NewWriteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent
NewWriteRowsEvent returns a WriteRows event. Uses v2.
func NewXIDEvent ¶
func NewXIDEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent
NewXIDEvent returns a XID event. We do not use the data, so keep it 0.
type BinlogFormat ¶
type BinlogFormat struct { // HeaderSizes is an array of sizes of the headers for each message. HeaderSizes []byte // ServerVersion is the name of the MySQL server version. // It starts with something like 5.6.33-xxxx. ServerVersion string // FormatVersion is the version number of the binlog file format. // We only support version 4. FormatVersion uint16 // HeaderLength is the size in bytes of event headers other // than FORMAT_DESCRIPTION_EVENT. Almost always 19. HeaderLength byte // ChecksumAlgorithm is the ID number of the binlog checksum algorithm. // See three possible values below. ChecksumAlgorithm byte }
BinlogFormat contains relevant data from the FORMAT_DESCRIPTION_EVENT. This structure is passed to subsequent event types to let them know how to parse themselves.
func NewMariaDBBinlogFormat ¶
func NewMariaDBBinlogFormat() BinlogFormat
NewMariaDBBinlogFormat returns a typical BinlogFormat for MariaDB 10.0.
func NewMySQL56BinlogFormat ¶
func NewMySQL56BinlogFormat() BinlogFormat
NewMySQL56BinlogFormat returns a typical BinlogFormat for MySQL 5.6.
func (BinlogFormat) HeaderSize ¶
func (f BinlogFormat) HeaderSize(typ byte) byte
HeaderSize returns the header size of any event type.
func (BinlogFormat) IsZero ¶
func (f BinlogFormat) IsZero() bool
IsZero returns true if the BinlogFormat has not been initialized.
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
Bitmap is used by the previous structures.
func NewServerBitmap ¶
NewServerBitmap returns a bitmap that can hold 'count' bits.
func (*Bitmap) BitCount ¶
BitCount returns how many bits are set in the bitmap. Note values that are not used may be set to 0 or 1, hence the non-efficient logic.
type CacheState ¶ added in v0.12.0
type CacheState int
CacheState is a state that is returned by the UserEntryWithCacheHash method from the CachingStorage interface. This state is needed to indicate whether the authentication is accepted, rejected by the cache itself or if the cache can't fullfill the request. In that case it indicates that with AuthNeedMoreData.
const ( // AuthRejected is used when the cache knows the request can be rejected. AuthRejected CacheState = iota // AuthAccepted is used when the cache knows the request can be accepted. AuthAccepted // AuthNeedMoreData is used when the cache doesn't know the answer and more data is needed. AuthNeedMoreData )
type CachingStorage ¶ added in v0.12.0
type CachingStorage interface {
UserEntryWithCacheHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, CacheState, error)
}
CachingStorage describes an object that is suitable to retrieve user information based on a hashed value of the password. This applies to the `caching_sha2_password` authentication method.
The cache would hash the password internally as `SHA256(SHA256(password))`.
The VerifyHashedCachingSha2Password helper method can be used to verify such a hash based on the salt and auth response provided here after retrieving the hashed password from the cache.
type Conn ¶
type Conn struct { // ClientData is a place where an application can store any // connection-related data. Mostly used on the server side, to // avoid maps indexed by ConnectionID for instance. ClientData any // ServerVersion is set during Connect with the server // version. It is not changed afterwards. It is unused for // server-side connections. ServerVersion string // User is the name used by the client to connect. // It is set during the initial handshake. User string // For server-side connections, listener points to the server object. // UserData is custom data returned by the AuthServer module. // It is set during the initial handshake. UserData Getter // PrepareData is the map to use a prepared statement. PrepareData map[uint32]*PrepareData // 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 // ConnectionID is set: // - at Connect() time for clients, with the value returned by // the server. // - at accept time for the server. ConnectionID uint32 // StatementID is the prepared statement ID. StatementID uint32 // 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 // CharacterSet is the charset for this connection, as negotiated // in our handshake with the server. Note that although the MySQL protocol lists this // as a "character set", the returned byte value is actually a Collation ID, // and hence it's casted as such here. // If the user has specified a custom Collation in the ConnParams for this // connection, once the CharacterSet has been negotiated, we will override // it via SQL and update this field accordingly. CharacterSet collations.ID // ExpectSemiSyncIndicator is applicable when the connection is used for replication (ComBinlogDump). // When 'true', events are assumed to be padded with 2-byte semi-sync information // See https://dev.mysql.com/doc/internals/en/semi-sync-binlog-event.html ExpectSemiSyncIndicator bool // 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 Connect ¶
func Connect(ctx context.Context, params *ConnParams) (*Conn, error)
Connect creates a connection to a server. It then handles the initial handshake.
If context is canceled before the end of the process, this function will return nil, ctx.Err().
FIXME(alainjobart) once we have more of a server side, add test cases to cover all failure scenarios.
func GetTestConn ¶ added in v0.18.0
func GetTestConn() *Conn
GetTestConn returns a conn for testing purpose only.
func GetTestServerConn ¶ added in v0.19.0
GetTestServerConn is only meant to be used for testing. It creates a server connection using a testConn and the provided listener.
func (*Conn) AnalyzeSemiSyncAckRequest ¶ added in v0.14.0
func (c *Conn) AnalyzeSemiSyncAckRequest(buf []byte) (strippedBuf []byte, ackRequested bool, err error)
AnalyzeSemiSyncAckRequest is given a packet and checks if the packet has a semi-sync Ack request. This is only applicable to binlog dump event packets. If semi sync information exists, then the function returns a stopped buf that should be then processed as the event data
func (*Conn) BaseShowTables ¶ added in v0.10.0
BaseShowTables returns a query that shows tables
func (*Conn) BaseShowTablesWithSizes ¶ added in v0.16.0
BaseShowTablesWithSizes returns a query that shows tables and their sizes
func (*Conn) CancelCtx ¶ added in v0.18.0
func (c *Conn) CancelCtx()
CancelCtx aborts an existing running query
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) CloseResult ¶
func (c *Conn) CloseResult()
CloseResult can be used to terminate a streaming query early. It just drains the remaining values.
func (*Conn) ConnCheck ¶ added in v0.19.0
ConnCheck ensures that this connection to the MySQL server hasn't been broken. This is a fast, non-blocking check. For details on its implementation, please read "Three Bugs in the Go MySQL Driver" (Vicent Marti, GitHub, 2020) https://github.blog/2020-05-20-three-bugs-in-the-go-mysql-driver/
func (*Conn) ExecuteFetch ¶
func (c *Conn) ExecuteFetch(query string, maxrows int, wantfields bool) (result *sqltypes.Result, err error)
ExecuteFetch executes a query and returns the result. Returns a SQLError. Depending on the transport used, the error returned might be different for the same condition:
1. if the server closes the connection when no command is in flight:
1.1 unix: WriteComQuery will fail with a 'broken pipe', and we'll return CRServerGone(2006). 1.2 tcp: WriteComQuery will most likely work, but readComQueryResponse will fail, and we'll return CRServerLost(2013). This is because closing a TCP socket on the server side sends a FIN to the client (telling the client the server is done writing), but on most platforms doesn't send a RST. So the client has no idea it can't write. So it succeeds writing data, which *then* triggers the server to send a RST back, received a bit later. By then, the client has already started waiting for the response, and will just return a CRServerLost(2013). So CRServerGone(2006) will almost never be seen with TCP. 2. if the server closes the connection when a command is in flight, readComQueryResponse will fail, and we'll return CRServerLost(2013).
func (*Conn) ExecuteFetchMulti ¶
func (c *Conn) ExecuteFetchMulti(query string, maxrows int, wantfields bool) (result *sqltypes.Result, more bool, err error)
ExecuteFetchMulti is for fetching multiple results from a multi-statement result. It returns an additional 'more' flag. If it is set, you must fetch the additional results using ReadQueryResult.
func (*Conn) ExecuteFetchWithWarningCount ¶
func (c *Conn) ExecuteFetchWithWarningCount(query string, maxrows int, wantfields bool) (result *sqltypes.Result, warnings uint16, err error)
ExecuteFetchWithWarningCount is for fetching results and a warning count Note: In a future iteration this should be abolished and merged into the ExecuteFetch API.
func (*Conn) ExecuteStreamFetch ¶
ExecuteStreamFetch starts a streaming query. Fields(), FetchNext() and CloseResult() can be called once this is successful. Returns a SQLError.
func (*Conn) FetchNext ¶
FetchNext returns the next result for an ongoing streaming query. It returns (nil, nil) if there is nothing more to read.
func (*Conn) GetGTIDMode ¶ added in v0.14.0
GetGTIDMode returns the tablet's GTID mode. Only available in MySQL flavour
func (*Conn) GetGTIDPurged ¶ added in v0.14.0
func (c *Conn) GetGTIDPurged() (replication.Position, error)
GetGTIDPurged returns the tablet's GTIDs which are purged.
func (*Conn) GetRawConn ¶ added in v0.11.0
GetRawConn returns the raw net.Conn for nefarious purposes.
func (*Conn) GetServerUUID ¶ added in v0.14.0
GetServerUUID returns the server's UUID.
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) IsMariaDB ¶
IsMariaDB returns true iff the other side of the client connection is identified as MariaDB. Most applications should not care, but this is useful in tests.
func (*Conn) IsMarkedForClose ¶ added in v0.18.0
IsMarkedForClose return true if the connection should be closed.
func (*Conn) IsShuttingDown ¶ added in v0.19.0
func (*Conn) IsUnixSocket ¶ added in v0.12.0
IsUnixSocket returns true if this connection is over a Unix socket.
func (*Conn) MarkForClose ¶ added in v0.18.0
func (c *Conn) MarkForClose()
MarkForClose marks the connection for close.
func (*Conn) PrimaryFilePosition ¶ added in v0.11.0
func (c *Conn) PrimaryFilePosition() (replication.Position, error)
PrimaryFilePosition returns the current primary's file based replication position.
func (*Conn) PrimaryPosition ¶ added in v0.11.0
func (c *Conn) PrimaryPosition() (replication.Position, error)
PrimaryPosition returns the current primary's replication position.
func (*Conn) ReadBinlogEvent ¶
func (c *Conn) ReadBinlogEvent() (BinlogEvent, error)
ReadBinlogEvent reads the next BinlogEvent. This must be used in conjunction with SendBinlogDumpCommand.
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) ReadQueryResult ¶
func (c *Conn) ReadQueryResult(maxrows int, wantfields bool) (*sqltypes.Result, bool, uint16, error)
ReadQueryResult gets the result from the last written query.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the underlying socket RemoteAddr().
func (*Conn) ResetReplicationCommands ¶
ResetReplicationCommands returns the commands to completely reset replication on the host.
func (*Conn) ResetReplicationParametersCommands ¶ added in v0.14.0
ResetReplicationParametersCommands returns the commands to reset replication parameters on the host.
func (*Conn) RestartReplicationCommands ¶
RestartReplicationCommands returns the commands to stop, reset and start replication.
func (*Conn) SemiSyncExtensionLoaded ¶
SemiSyncExtensionLoaded checks if the semisync extension has been loaded. It should work for both MariaDB and MySQL.
func (*Conn) SendBinlogDumpCommand ¶
func (c *Conn) SendBinlogDumpCommand(serverID uint32, binlogFilename string, startPos replication.Position) error
SendBinlogDumpCommand sends the flavor-specific version of the COM_BINLOG_DUMP command to start dumping raw binlog events over a server connection, starting at a given GTID.
func (*Conn) SendSemiSyncAck ¶ added in v0.14.0
SendSemiSyncAck sends an ACK to the source, in response to binlog events the source has tagged with a SEMI_SYNC_ACK_REQ see https://dev.mysql.com/doc/internals/en/semi-sync-ack-packet.html
func (*Conn) ServerVersionAtLeast ¶ added in v0.14.0
ServerVersionAtLeast returns 'true' if server version is equal or greater than given parts. e.g. "8.0.14-log" is at least [8, 0, 13] and [8, 0, 14], but not [8, 0, 15]
func (*Conn) SetReplicationPositionCommands ¶
func (c *Conn) SetReplicationPositionCommands(pos replication.Position) []string
SetReplicationPositionCommands returns the commands to set the replication position at which the replica will resume when it is later reparented with SetReplicationSourceCommand.
func (*Conn) SetReplicationSourceCommand ¶ added in v0.11.0
func (c *Conn) SetReplicationSourceCommand(params *ConnParams, host string, port int32, connectRetry int) string
SetReplicationSourceCommand returns the command to use the provided host/port as the new replication source (without changing any GTID position). It is guaranteed to be called with replication stopped. It should not start or stop replication.
func (*Conn) ShowPrimaryStatus ¶ added in v0.11.0
func (c *Conn) ShowPrimaryStatus() (replication.PrimaryStatus, error)
ShowPrimaryStatus executes the right SHOW MASTER STATUS command, and returns a parsed executed Position, as well as file based Position.
func (*Conn) ShowReplicationStatus ¶
func (c *Conn) ShowReplicationStatus() (replication.ReplicationStatus, error)
ShowReplicationStatus executes the right command to fetch replication status, and returns a parsed Position with other fields.
func (*Conn) StartReplicationCommand ¶
StartReplicationCommand returns the command to start replication.
func (*Conn) StartReplicationUntilAfterCommand ¶
func (c *Conn) StartReplicationUntilAfterCommand(pos replication.Position) string
StartReplicationUntilAfterCommand returns the command to start replication.
func (*Conn) StartSQLThreadCommand ¶ added in v0.13.0
StartSQLThreadCommand returns the command to start the replica's SQL thread.
func (*Conn) StartSQLThreadUntilAfterCommand ¶ added in v0.13.2
func (c *Conn) StartSQLThreadUntilAfterCommand(pos replication.Position) string
StartSQLThreadUntilAfterCommand returns the command to start the replica's SQL thread(s) and have it run until it has reached the given position, at which point it will stop.
func (*Conn) StopIOThreadCommand ¶
StopIOThreadCommand returns the command to stop the replica's io thread.
func (*Conn) StopReplicationCommand ¶
StopReplicationCommand returns the command to stop the replication.
func (*Conn) StopSQLThreadCommand ¶ added in v0.13.2
StopSQLThreadCommand returns the command to stop the replica's SQL thread(s).
func (*Conn) SupportsCapability ¶ added in v0.14.0
func (c *Conn) SupportsCapability(capability capabilities.FlavorCapability) (bool, error)
SupportsCapability checks if the database server supports the given capability
func (*Conn) TLSEnabled ¶ added in v0.12.0
TLSEnabled returns true if this connection is using TLS.
func (*Conn) UpdateCancelCtx ¶ added in v0.18.0
func (c *Conn) UpdateCancelCtx(cancel context.CancelFunc)
UpdateCancelCtx updates the cancel function on the connection.
func (*Conn) WaitUntilFilePosition ¶ added in v0.19.0
WaitUntilFilePosition waits until the given position is reached or until the context expires for the file position flavor. It returns an error if we did not succeed.
func (*Conn) WaitUntilPosition ¶ added in v0.19.0
WaitUntilPosition waits until the given position is reached or until the context expires. It returns an error if we did not succeed.
func (*Conn) WriteBinlogEvent ¶ added in v0.16.0
func (c *Conn) WriteBinlogEvent(ev BinlogEvent, semiSyncEnabled bool) error
WriteBinlogEvent writes a binlog event as part of a replication stream https://dev.mysql.com/doc/internals/en/binlog-network-stream.html https://dev.mysql.com/doc/internals/en/binlog-event.html
func (*Conn) WriteComBinlogDump ¶
func (c *Conn) WriteComBinlogDump(serverID uint32, binlogFilename string, binlogPos uint32, flags uint16) error
WriteComBinlogDump writes a ComBinlogDump command. See http://dev.mysql.com/doc/internals/en/com-binlog-dump.html for syntax. Returns a SQLError.
func (*Conn) WriteComBinlogDumpGTID ¶
func (c *Conn) WriteComBinlogDumpGTID(serverID uint32, binlogFilename string, binlogPos uint64, flags uint16, gtidSet []byte) error
WriteComBinlogDumpGTID writes a ComBinlogDumpGTID command. Only works with MySQL 5.6+ (and not MariaDB). See http://dev.mysql.com/doc/internals/en/com-binlog-dump-gtid.html for syntax.
func (*Conn) WriteComQuery ¶
WriteComQuery writes a query for the server to execute. Client -> Server. Returns SQLError(CRServerGone) if it can't.
func (*Conn) WriteErrorAndLog ¶ added in v0.16.0
type ConnParams ¶
type ConnParams struct { Host string Port int Uname string Pass string DbName string UnixSocket string Charset collations.ID Flags uint64 Flavor string // The following SSL flags control the SSL behavior. // // Not setting this value implies preferred mode unless // the CapabilityClientSSL bit is set in db_flags. In the // flag is set, it ends up equivalent to verify_identity mode. SslMode vttls.SslMode SslCa string SslCaPath string SslCert string SslCrl string SslKey string TLSMinVersion string ServerName string ConnectTimeoutMs uint64 // The following is only set to force the client to connect without // using CapabilityClientDeprecateEOF DisableClientDeprecateEOF bool // EnableQueryInfo sets whether the results from queries performed by this // connection should include the 'info' field that MySQL usually returns. This 'info' // field usually contains a human-readable text description of the executed query // for informative purposes. It has no programmatic value. Returning this field is // disabled by default. EnableQueryInfo bool // FlushDelay is the delay after which buffered response will be flushed to the client. FlushDelay time.Duration TruncateErrLen int }
ConnParams contains all the parameters to use to connect to mysql.
func (*ConnParams) EffectiveSslMode ¶ added in v0.12.0
func (cp *ConnParams) EffectiveSslMode() vttls.SslMode
EffectiveSslMode computes the effective SslMode. If SslMode is explicitly set, it uses that to determine this, if it's not set it falls back to the legacy db_flags behavior.
func (*ConnParams) EnableClientFoundRows ¶
func (cp *ConnParams) EnableClientFoundRows()
EnableClientFoundRows sets the flag for CLIENT_FOUND_ROWS.
func (*ConnParams) EnableSSL ¶
func (cp *ConnParams) EnableSSL()
EnableSSL will set the right flag on the parameters.
func (*ConnParams) SslEnabled ¶
func (cp *ConnParams) SslEnabled() bool
SslEnabled returns if SSL is enabled. If the effective ssl mode is preferred, it checks the unix socket and hostname to see if we're not connecting to local MySQL.
func (*ConnParams) SslRequired ¶ added in v0.12.0
func (cp *ConnParams) SslRequired() bool
SslRequired returns whether the connection parameters define that SSL is a requirement. If SslMode is set, it uses that to determine this, if it's not set it falls back to the legacy db_flags behavior.
type FakeBinlogStream ¶
type FakeBinlogStream struct { // ServerID is the server ID of the originating mysql-server. ServerID uint32 // LogPosition is an incrementing log position. LogPosition uint32 // Timestamp is a uint32 of when the events occur. It is not changed. Timestamp uint32 }
FakeBinlogStream is used to generate consistent BinlogEvent packets for a stream. It makes sure the ServerID and log positions are reasonable.
func NewFakeBinlogStream ¶
func NewFakeBinlogStream() *FakeBinlogStream
NewFakeBinlogStream returns a simple FakeBinlogStream.
func (*FakeBinlogStream) Packetize ¶
func (s *FakeBinlogStream) Packetize(f BinlogFormat, typ byte, flags uint16, data []byte) []byte
Packetize adds the binlog event header to a packet, and optionally the checksum.
type Handler ¶
type Handler interface { // NewConnection is called when a connection is created. // It is not established yet. The handler can decide to // set StatusFlags that will be returned by the handshake methods. // In particular, ServerStatusAutocommit might be set. NewConnection(c *Conn) // ConnectionReady is called after the connection handshake, but // before we begin to process commands. ConnectionReady(c *Conn) // ConnectionClosed is called when a connection is closed. ConnectionClosed(c *Conn) // ComQuery is called when a connection receives a query. // Note the contents of the query slice may change after // the first call to callback. So the Handler should not // hang on to the byte slice. ComQuery(c *Conn, query string, callback func(*sqltypes.Result) error) error // ComPrepare is called when a connection receives a prepared // statement query. ComPrepare(c *Conn, query string, bindVars map[string]*querypb.BindVariable) ([]*querypb.Field, error) // ComStmtExecute is called when a connection receives a statement // execute query. ComStmtExecute(c *Conn, prepare *PrepareData, callback func(*sqltypes.Result) error) error // ComRegisterReplica is called when a connection receives a ComRegisterReplica request ComRegisterReplica(c *Conn, replicaHost string, replicaPort uint16, replicaUser string, replicaPassword string) error // ComBinlogDump is called when a connection receives a ComBinlogDump request ComBinlogDump(c *Conn, logFile string, binlogPos uint32) error // ComBinlogDumpGTID is called when a connection receives a ComBinlogDumpGTID request ComBinlogDumpGTID(c *Conn, logFile string, logPos uint64, gtidSet replication.GTIDSet) error // WarningCount is called at the end of each query to obtain // the value to be returned to the client in the EOF packet. // Note that this will be called either in the context of the // ComQuery callback if the result does not contain any fields, // or after the last ComQuery call completes. WarningCount(c *Conn) uint16 ComResetConnection(c *Conn) Env() *vtenv.Environment }
A Handler is an interface used by Listener to send queries. The implementation of this interface may store data in the ClientData field of the Connection for its own purposes.
For a given Connection, all these methods are serialized. It means only one of these methods will be called concurrently for a given Connection. So access to the Connection ClientData does not need to be protected by a mutex.
However, each connection is using one go routine, so multiple Connection objects can call these concurrently, for different Connections.
type HashStorage ¶ added in v0.12.0
type HashStorage interface {
UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error)
}
HashStorage describes an object that is suitable to retrieve user information based on the hashed authentication response for mysql_native_password.
In general, an implementation of this would use an internally stored password that is hashed twice with SHA1.
The VerifyHashedMysqlNativePassword helper method can be used to verify such a hash based on the salt and auth response provided here after retrieving the hashed password from the storage.
type Listener ¶
type Listener struct { // ServerVersion is the version we will advertise. ServerVersion string // TLSConfig is the server TLS config. If set, we will advertise // that we support SSL. // atomic value stores *tls.Config TLSConfig atomic.Value // AllowClearTextWithoutTLS needs to be set for the // mysql_clear_password authentication method to be accepted // by the server when TLS is not in use. AllowClearTextWithoutTLS atomic.Bool // SlowConnectWarnThreshold if non-zero specifies an amount of time // beyond which a warning is logged to identify the slow connection SlowConnectWarnThreshold atomic.Int64 // RequireSecureTransport configures the server to reject connections from insecure clients RequireSecureTransport bool // PreHandleFunc is called for each incoming connection, immediately after // accepting a new connection. By default it's no-op. Useful for custom // connection inspection or TLS termination. The returned connection is // handled further by the MySQL handler. An non-nil error will stop // processing the connection by the MySQL handler. PreHandleFunc func(context.Context, net.Conn, uint32) (net.Conn, error) // contains filtered or unexported fields }
Listener is the MySQL server protocol listener.
func NewFromListener ¶
func NewFromListener( l net.Listener, authServer AuthServer, handler Handler, connReadTimeout time.Duration, connWriteTimeout time.Duration, connBufferPooling bool, keepAlivePeriod time.Duration, flushDelay time.Duration, ) (*Listener, error)
NewFromListener creates a new mysql listener from an existing net.Listener
func NewListener ¶
func NewListener( protocol, address string, authServer AuthServer, handler Handler, connReadTimeout time.Duration, connWriteTimeout time.Duration, proxyProtocol bool, connBufferPooling bool, keepAlivePeriod time.Duration, flushDelay time.Duration, ) (*Listener, error)
NewListener creates a new Listener.
func NewListenerWithConfig ¶
func NewListenerWithConfig(cfg ListenerConfig) (*Listener, error)
NewListenerWithConfig creates new listener using provided config. There are no default values for config, so caller should ensure its correctness.
func (*Listener) Accept ¶
func (l *Listener) Accept()
Accept runs an accept loop until the listener is closed.
type ListenerConfig ¶
type ListenerConfig struct { // Protocol-Address pair and Listener are mutually exclusive parameters Protocol string Address string Listener net.Listener AuthServer AuthServer Handler Handler ConnReadTimeout time.Duration ConnWriteTimeout time.Duration ConnReadBufferSize int ConnBufferPooling bool ConnKeepAlivePeriod time.Duration FlushDelay time.Duration }
ListenerConfig should be used with NewListenerWithConfig to specify listener parameters.
type NoneGetter ¶
type NoneGetter struct{}
NoneGetter holds the empty string
func (*NoneGetter) Get ¶
func (ng *NoneGetter) Get() *querypb.VTGateCallerID
Get returns the empty string
type PacketComStmtPrepareOK ¶ added in v0.9.0
type PacketComStmtPrepareOK struct {
// contains filtered or unexported fields
}
PacketComStmtPrepareOK contains the COM_STMT_PREPARE_OK packet details
type PacketOK ¶ added in v0.9.0
type PacketOK struct {
// contains filtered or unexported fields
}
PacketOK contains the ok packet details
type PlainTextStorage ¶ added in v0.12.0
type PlainTextStorage interface {
UserEntryWithPassword(conn *Conn, user string, password string, remoteAddr net.Addr) (Getter, error)
}
PlainTextStorage describes an object that is suitable to retrieve user information based on the plain text password of a user. This can be obtained through various Mysql authentication methods, such as `mysql_clear_passwrd`, `dialog` or `caching_sha2_password` in the full authentication handshake case of the latter.
This mechanism also would allow for picking your own password storage in the backend, such as BCrypt, SCrypt, PBKDF2 or Argon2 once the plain text is obtained.
When comparing plain text passwords directly, please ensure to use `subtle.ConstantTimeCompare` to prevent timing based attacks on the password.
type PrepareData ¶
type PrepareData struct { ParamsType []int32 ColumnNames []string PrepareStmt string BindVars map[string]*querypb.BindVariable StatementID uint32 ParamsCount uint16 }
PrepareData is a buffer used for store prepare statement meta data
type Query ¶
type Query struct { Database string Charset *binlogdatapb.Charset SQL string }
Query contains data from a QUERY_EVENT.
type Row ¶
type Row struct { // NullIdentifyColumns describes which of the identify columns are NULL. // It is only set for UPDATE and DELETE events. NullIdentifyColumns Bitmap // NullColumns describes which of the present columns are NULL. // It is only set for WRITE and UPDATE events. NullColumns Bitmap // Identify is the raw data for the columns used to identify a row. // It is only set for UPDATE and DELETE events. Identify []byte // Data is the raw data. // It is only set for WRITE and UPDATE events. Data []byte }
Row contains data for a single Row in a Rows event.
type Rows ¶
type Rows struct { // Flags has the flags from the event. Flags uint16 // IdentifyColumns describes which columns are included to // identify the row. It is a bitmap indexed by the TableMap // list of columns. // Set for UPDATE and DELETE. IdentifyColumns Bitmap // DataColumns describes which columns are included. It is // a bitmap indexed by the TableMap list of columns. // Set for WRITE and UPDATE. DataColumns Bitmap // Rows is an array of Row in the event. Rows []Row }
Rows contains data from a {WRITE,UPDATE,DELETE}_ROWS_EVENT.
func (*Rows) StringIdentifiesForTests ¶
StringIdentifiesForTests is a helper method to return the string identify of all columns in a row in a Row. Only use it in tests, as the returned values cannot be interpreted correctly without the schema. We assume everything is unsigned in this method.
func (*Rows) StringValuesForTests ¶
StringValuesForTests is a helper method to return the string value of all columns in a row in a Row. Only use it in tests, as the returned values cannot be interpreted correctly without the schema. We assume everything is unsigned in this method.
type StaticUserData ¶
StaticUserData holds the username and groups
func (*StaticUserData) Get ¶
func (sud *StaticUserData) Get() *querypb.VTGateCallerID
Get returns the wrapped username and groups
type TableMap ¶
type TableMap struct { // Flags is the table's flags. Flags uint16 // Database is the database name. Database string // Name is the name of the table. Name string // Types is an array of MySQL types for the fields. Types []byte // CanBeNull's bits are set if the column can be NULL. CanBeNull Bitmap // Metadata is an array of uint16, one per column. // It contains a few extra information about each column, // that is dependent on the type. // - If the metadata is not present, this is zero. // - If the metadata is one byte, only the lower 8 bits are used. // - If the metadata is two bytes, all 16 bits are used. Metadata []uint16 }
TableMap contains data from a TABLE_MAP_EVENT.
type TransactionPayload ¶ added in v0.17.0
type TransactionPayload struct { Size uint64 CompressionType uint64 UncompressedSize uint64 Payload []byte Events []BinlogEvent }
func (*TransactionPayload) Decode ¶ added in v0.17.0
func (tp *TransactionPayload) Decode(data []byte) error
Decode decodes and decompresses the payload.
type UnimplementedHandler ¶ added in v0.13.0
type UnimplementedHandler struct{}
UnimplementedHandler implemnts all of the optional callbacks so as to satisy the Handler interface. Intended to be embedded into your custom Handler implementation without needing to define every callback and to help be forwards compatible when new functions are added.
func (UnimplementedHandler) ComResetConnection ¶ added in v0.13.0
func (UnimplementedHandler) ComResetConnection(*Conn)
func (UnimplementedHandler) ConnectionClosed ¶ added in v0.13.0
func (UnimplementedHandler) ConnectionClosed(*Conn)
func (UnimplementedHandler) ConnectionReady ¶ added in v0.13.0
func (UnimplementedHandler) ConnectionReady(*Conn)
func (UnimplementedHandler) NewConnection ¶ added in v0.13.0
func (UnimplementedHandler) NewConnection(*Conn)
type UserValidator ¶ added in v0.12.0
UserValidator is an interface that allows checking if a specific user will work for an auth method. This interface is called by all the default helpers that create AuthMethod instances for the various supported Mysql authentication methods.
Source Files ¶
- auth_server.go
- auth_server_clientcert.go
- auth_server_none.go
- auth_server_static.go
- binlog_dump.go
- binlog_event.go
- binlog_event_common.go
- binlog_event_compression.go
- binlog_event_filepos.go
- binlog_event_make.go
- binlog_event_mariadb.go
- binlog_event_mysql56.go
- binlog_event_rbr.go
- charset.go
- client.go
- conn.go
- conn_fake.go
- conn_params.go
- conn_unix.go
- constants.go
- doc.go
- encoding.go
- flavor.go
- flavor_filepos.go
- flavor_mariadb.go
- flavor_mariadb_binlog_playback.go
- flavor_mysql.go
- flavor_mysqlgr.go
- innodb_constants.go
- query.go
- register_replica.go
- replication.go
- replication_constants.go
- schema.go
- server.go
- streaming_query.go
Directories ¶
Path | Synopsis |
---|---|
charset/korean
Package korean provides Korean encodings such as EUC-KR.
|
Package korean provides Korean encodings such as EUC-KR. |
charset/simplifiedchinese
Package simplifiedchinese provides Simplified Chinese encodings such as GBK.
|
Package simplifiedchinese provides Simplified Chinese encodings such as GBK. |
vindex
text is a repository of text-related packages related to internationalization (i18n) and localization (l10n), such as character encodings, text transformations, and locale-specific text handling.
|
text is a repository of text-related packages related to internationalization (i18n) and localization (l10n), such as character encodings, text transformations, and locale-specific text handling. |
vindex/collate
Package collate contains types for comparing and sorting Unicode strings according to a given collation order.
|
Package collate contains types for comparing and sorting Unicode strings according to a given collation order. |
vindex/unicode
unicode holds packages with implementations of Unicode standards that are mostly used as building blocks for other packages in vitess.io/vitess/go/mysql/collations/vindex, layout engines, or are otherwise more low-level in nature.
|
unicode holds packages with implementations of Unicode standards that are mostly used as building blocks for other packages in vitess.io/vitess/go/mysql/collations/vindex, layout engines, or are otherwise more low-level in nature. |
vindex/unicode/norm
Package norm contains types and functions for normalizing Unicode strings.
|
Package norm contains types and functions for normalizing Unicode strings. |
Package endtoend is a test-only package.
|
Package endtoend is a test-only package. |
Package fakesqldb provides a MySQL server for tests.
|
Package fakesqldb provides a MySQL server for tests. |