Documentation ¶
Index ¶
- Constants
- Variables
- type Conn
- func (c *Conn) Close()
- func (c *Conn) Connect(ds *DataSource, database string) error
- func (c *Conn) Exec(command string, args ...interface{}) (*PacketOK, error)
- func (c *Conn) GetHandshakeInfo(si *HandshakeInfo)
- func (c *Conn) GetStatus() int64
- func (c *Conn) Read(p []byte) (n int, err error)
- func (c *Conn) ReadPacket() ([]byte, error)
- func (c *Conn) RegisterSlave(rc *ReplicationConfig) error
- func (c *Conn) SetKeepalive(d time.Duration) bool
- func (c *Conn) SetReadTimeout(dura time.Duration)
- func (c *Conn) StartDumpBinlog(pos ReplicationPoint) error
- func (c *Conn) WritePacket(data []byte) error
- type DBConfig
- type DataSource
- type Field
- type HandshakeInfo
- type LenencInt
- type LenencString
- type PacketBinlogDump
- type PacketComStr
- type PacketEOF
- type PacketErr
- type PacketHandshake
- type PacketHandshakeResponse
- type PacketHeader
- type PacketMySQL
- type PacketOK
- type PacketRegisterSlave
- type ReplicationConfig
- type ReplicationPoint
- type ResultSet
Constants ¶
const ( FieldTypeDecimal = iota FieldTypeTiny FieldTypeShort FieldTypeLong FieldTypeFloat FieldTypeDouble FieldTypeNull FieldTypeTimestamp FieldTypeLongLong FieldTypeInt24 FieldTypeDate FieldTypeTime FieldTypeDateTime FieldTypeYear FieldTypeNewDate FieldTypeVarChar FieldTypeBit FieldTypeTimestamp2 FieldTypeDateTime2 FieldTypeTime2 )
FieldType is type of mysql field
const ( FieldTypeJSON = 0xf5 + iota FieldTypeNewDecimal FieldTypeEnum FieldTypeSet FieldTypeTinyBlob FieldTypeMediumBlob FieldTypeLongBlob FieldTypeBlob FieldTypeVarString FieldTypeString FieldTypeGeometry )
FieldType is type of mysql field
const ( PacketHeaderOK = 0x00 PacketHeaderEOF = 0xfe PacketHeaderLocalInFile = 0xfb PacketHeaderERR = 0xff )
const ( CharsetBig5ChineseCI // 1 CharsetLatin2CzechCS // 2 CharsetDec8SwedishCI // 3 CharsetCp850GeneralCI // 4 CharsetGerman1CI // 5 CharsetHp8EnglishCI // 6 CharsetKoi8rGeneralCI // 7 CharsetLatin1SwedishCI // 8 CharsetLatin2GeneralCI // 9 CharsetSwe7SwedishCI // 10 CharsetAsciiGeneralCI // 11 CharsetUjisJapaneseCI // 12 CharsetSjisJapaneseCI // 13 CharsetCp1251BulgarianCI // 14 CharsetLatin1DanishCI // 15 CharsetHebrewGeneralCI // 16 CharsetMissing1 // 17 CharsetTis620ThaiCI // 18 CharsetEuckrKoreanCI // 19 CharsetLatin7EstonianCS // 20 CharsetLatin2HungarianCI // 21 CharsetKoi8uGeneralCI // 22 CharsetCp1251UkrainianCI // 23 CharsetGb2312ChineseCI // 24 CharsetGreekGeneralCI // 25 CharsetCp1250GeneralCI // 26 CharsetLatin2CroatianCI // 27 CharsetGbkChineseCI // 28 CharsetCp1257LithuanianCI // 29 CharsetLatin5KurkishCI // 30 CharsetLatin1German2CI // 31 CharsetArmscii8GeneralCI // 32 CharsetUtf8GeneralCI // 33 )
Charset SELECT id, collation_name FROM information_schema.collations ORDER BY id; https://dev.mysql.com/doc/internals/en/character-set.html#packet-Protocol::CharacterSet Not all charset ...
const (
// MySQLNativePasswordPlugin is the mysql native password auth type
MySQLNativePasswordPlugin = "mysql_native_password"
)
Variables ¶
var ( // ErrNoData no datas in the result set ErrNoData = errors.New("No data in the result set") // ErrColumnOutOfRange represent the index if out of column count ErrColumnOutOfRange = errors.New("Index out of column range") // ErrInvalidConn returns when connection is invalid ErrInvalidConn = errors.New("Invalid conn") // ErrRowNotFree represents the connection has a query and not closed ErrRowNotFree = errors.New("Query row not free") // ErrWrongFieldType returns when get field data with wrong type ErrWrongFieldType = errors.New("Wrong field type") )
var ( // ErrMalformPacket represents a response with the unknown header ErrMalformPacket = errors.New("Malform packet format") )
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a connection communicate with the mysql server
func (*Conn) Connect ¶
func (c *Conn) Connect(ds *DataSource, database string) error
Connect connects to the mysql server
func (*Conn) GetHandshakeInfo ¶
func (c *Conn) GetHandshakeInfo(si *HandshakeInfo)
GetHandshakeInfo get the server information by handshake
func (*Conn) ReadPacket ¶
ReadPacket reads the full packet from mysql
func (*Conn) RegisterSlave ¶
func (c *Conn) RegisterSlave(rc *ReplicationConfig) error
RegisterSlave register the connection as a slave connection
func (*Conn) SetKeepalive ¶
SetKeepalive enables the tcp keepalive
func (*Conn) SetReadTimeout ¶
SetReadTimeout set the read timeout duration
func (*Conn) StartDumpBinlog ¶
func (c *Conn) StartDumpBinlog(pos ReplicationPoint) error
StartDumpBinlog start dump binlog from master
func (*Conn) WritePacket ¶
WritePacket writes the packet to mysql, data must has 4 bytes unused in head
type DBConfig ¶
type DBConfig struct { Type string `json:"type" toml:"type"` Host string `json:"host" toml:"host"` Port uint16 `json:"port" toml:"port"` Username string `json:"username" toml:"username"` Password string `json:"password" toml:"password"` Charset string `json:"charset" toml:"charset"` }
DBConfig is the connection information to db server
type DataSource ¶
type DataSource struct { Host string `json:"host" toml:"host"` Port uint16 `json:"port" toml:"port"` Username string `json:"username" toml:"username"` Password string `json:"password" toml:"password"` }
DataSource is a mysql instance to pull binlog stream
func (*DataSource) Address ¶
func (s *DataSource) Address() string
Address returns the address of the data source
type HandshakeInfo ¶
HandshakeInfo represents the mysql server information returned by handshake
func (*HandshakeInfo) String ¶
func (i *HandshakeInfo) String() string
type LenencInt ¶
LenencInt is a length encoded integer type https://dev.mysql.com/doc/internals/en/integer.html#length-encoded-integer
type LenencString ¶
LenencString is a length prefixed string
func (*LenencString) FromData ¶
func (s *LenencString) FromData(data []byte) int
FromData parse binary data to lenenc string
type PacketBinlogDump ¶
PacketBinlogDump to enable replication
func (*PacketBinlogDump) Encode ¶
func (p *PacketBinlogDump) Encode() ([]byte, error)
Encode encodes the packet to binary data
type PacketComStr ¶
type PacketComStr struct {
// contains filtered or unexported fields
}
PacketComStr is used to send the server a text-based query that is executed immediately
func (*PacketComStr) Encode ¶
func (p *PacketComStr) Encode() ([]byte, error)
Encode encodes the packet to binary data
type PacketEOF ¶
type PacketEOF struct {
// contains filtered or unexported fields
}
PacketEOF represents the eof of packets
type PacketErr ¶
type PacketErr struct { Header uint8 // ERR packet fields ErrorCode uint16 State string ErrorMessage string // contains filtered or unexported fields }
PacketErr parses mysql OK_Packet https://dev.mysql.com/doc/internals/en/packet-ERR_Packet.html
type PacketHandshake ¶
type PacketHandshake struct { ProtocolVersion uint8 ServerVersion string ConnectionID uint32 AuthPluginDataPart []byte Filter uint8 CapabilityFlags uint32 CharacterSet uint8 StatusFlags uint16 AuthPluginName string }
PacketHandshake is handshake packet sending from server
func (*PacketHandshake) Decode ¶
func (p *PacketHandshake) Decode(data []byte) error
Decode read binary data into handshake packet https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake
type PacketHandshakeResponse ¶
type PacketHandshakeResponse struct { CapabilityFlags uint32 MaxPacketSize uint32 Charset uint8 // Reserved [23]byte not used Username string // string[null] Password string AuthResponseLength LenencInt Database string // Decode part AuthPluginData []byte // contains filtered or unexported fields }
PacketHandshakeResponse responses the handshake packet to server https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse
func (*PacketHandshakeResponse) Encode ¶
func (p *PacketHandshakeResponse) Encode() []byte
Encode serialize the handshake response
type PacketHeader ¶
type PacketHeader [4]byte
PacketHeader is the header of the mysql packet to read the packet length and sequence
func (*PacketHeader) GetLength ¶
func (p *PacketHeader) GetLength() int
GetLength returns the header length
func (*PacketHeader) GetSequence ¶
func (p *PacketHeader) GetSequence() uint8
GetSequence returns the header sequence
func (*PacketHeader) SetLength ¶
func (p *PacketHeader) SetLength(v int)
SetLength set the length into underlying array
func (*PacketHeader) SetSequence ¶
func (p *PacketHeader) SetSequence(v uint8)
SetSequence sets the packet sequence
func (*PacketHeader) ToSlice ¶
func (p *PacketHeader) ToSlice() []byte
ToSlice returns a slice reference to the underlying array
type PacketMySQL ¶
PacketMySQL defines mysql packet interface
type PacketOK ¶
type PacketOK struct { Header uint8 // OK packet fields AffectedRows uint64 LastInsertID uint64 StatusFlags uint16 // StatusFlags has value : client protocol 41 or client transactions Warnings uint16 // EOF EOF bool // Result set ColumnCount LenencInt Results *ResultSet // contains filtered or unexported fields }
PacketOK parses mysql OK_Packet https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html
type PacketRegisterSlave ¶
type PacketRegisterSlave struct { ServerID uint32 Hostname string User string Password string Port uint16 Rank uint32 MasterID uint32 }
PacketRegisterSlave register slave to master https://dev.mysql.com/doc/internals/en/com-register-slave.html
func (*PacketRegisterSlave) Encode ¶
func (p *PacketRegisterSlave) Encode() ([]byte, error)
Encode encodes the packet to binary data
type ReplicationConfig ¶
type ReplicationConfig struct { SlaveID uint32 `json:"slave-id" toml:"slave-id"` //Pos Position `json:"position" toml:"position"` EnableGtid bool `json:"enable-gtid" toml:"enable-gtid"` EventBufferSize int `json:"event-buffer-size" toml:"event-buffer-size"` KeepAlivePeriod int `json:"keepalive-period" toml:"keepalive-period"` }
ReplicationConfig specify the master information
type ReplicationPoint ¶
Position represents a binlog replication position, slave can start sync with the position