Documentation ¶
Overview ¶
Package protocol implements parts of MySQL wire protocol which are needed for the service to be able to interpret the protocol messages but are not readily available in the convenient form in the vendored MySQL library.
For example, reading protocol packets from connections, parsing them and writing them to connections.
The following resources are helpful to understand protocol details.
Packet structure:
https://dev.mysql.com/doc/internals/en/mysql-packet.html
Generic response packets:
https://dev.mysql.com/doc/internals/en/generic-response-packets.html
Packets sent in the command phase:
https://dev.mysql.com/doc/internals/en/command-phase.html
Index ¶
- func FetchMySQLVersionInternal(ctx context.Context, dialer client.Dialer, databaseURI string) (string, error)
- func ReadPacket(conn io.Reader) (pkt []byte, pktType byte, err error)
- func WritePacket(pkt []byte, conn io.Writer) (int, error)
- type ChangeUser
- type CreateDB
- type Debug
- type DropDB
- type Error
- type Generic
- type InitDB
- type OK
- type Packet
- type ProcessKill
- type Query
- type Quit
- type Refresh
- type ShutDown
- type StatementBulkExecutePacket
- type StatementClosePacket
- type StatementExecutePacket
- type StatementFetchPacket
- type StatementPreparePacket
- type StatementResetPacket
- type StatementSendLongDataPacket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchMySQLVersionInternal ¶
func FetchMySQLVersionInternal(ctx context.Context, dialer client.Dialer, databaseURI string) (string, error)
FetchMySQLVersionInternal connects to a MySQL instance with provided dialer and tries to read the server version from initial handshake message. Error is returned in case of connection failure or when MySQL returns ERR package.
func ReadPacket ¶
ReadPacket reads a protocol packet from the connection.
MySQL wire protocol packet has the following structure:
4-byte header payload ________ _________ ... | | |
xx xx xx xx xx xx xx xx ...
|_____| | | payload | message length | type | sequence number
Types ¶
type ChangeUser ¶
type ChangeUser struct {
// contains filtered or unexported fields
}
ChangeUser represents the COM_CHANGE_USER command.
https://dev.mysql.com/doc/internals/en/com-change-user.html https://mariadb.com/kb/en/com_change_user/
type CreateDB ¶
type CreateDB struct {
// contains filtered or unexported fields
}
CreateDB represents the COM_CREATE_DB command.
https://dev.mysql.com/doc/internals/en/com-create-db.html https://mariadb.com/kb/en/com_create_db/
COM_CREATE_DB creates a schema. COM_CREATE_DB is deprecated in both MySQL and MariaDB.
func (*CreateDB) SchemaName ¶
func (p *CreateDB) SchemaName() string
SchemaName returns the schema name.
type Debug ¶
type Debug struct {
// contains filtered or unexported fields
}
Debug represents the COM_DEBUG command.
https://dev.mysql.com/doc/internals/en/com-debug.html https://mariadb.com/kb/en/com_debug/
COM_DEBUG forces the server to dump debug information to stdout. COM_DEBUG requires SUPER privileges.
type DropDB ¶
type DropDB struct {
// contains filtered or unexported fields
}
DropDB represents the COM_DROP_DB command.
https://dev.mysql.com/doc/internals/en/com-drop-db.html https://mariadb.com/kb/en/com_drop_db/
COM_DROP_DB drops a schema. COM_DROP_DB is deprecated in both MySQL and MariaDB.
func (*DropDB) SchemaName ¶
func (p *DropDB) SchemaName() string
SchemaName returns the schema name.
type Error ¶
type Error struct { // Message is the error Message Message string // Code is the error Code. Code uint16 // contains filtered or unexported fields }
Error represents the ERR packet.
https://dev.mysql.com/doc/internals/en/packet-ERR_Packet.html https://mariadb.com/kb/en/err_packet/
type Generic ¶
type Generic struct {
// contains filtered or unexported fields
}
Generic represents a generic packet other than the ones recognized below.
type InitDB ¶
type InitDB struct {
// contains filtered or unexported fields
}
InitDB represents the COM_INIT_DB command.
COM_INIT_DB is used to specify the default schema for the connection. For example, "USE <schema name>" from "mysql" client sends COM_INIT_DB command with the schema name.
https://dev.mysql.com/doc/internals/en/com-init-db.html https://mariadb.com/kb/en/com_init_db/
func (*InitDB) SchemaName ¶
func (p *InitDB) SchemaName() string
SchemaName returns the schema name.
type OK ¶
type OK struct {
// contains filtered or unexported fields
}
OK represents the OK packet.
https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html https://mariadb.com/kb/en/ok_packet/
type Packet ¶
type Packet interface { // Bytes returns the packet as raw bytes. Bytes() []byte }
Packet is the common interface for MySQL wire protocol packets.
type ProcessKill ¶
type ProcessKill struct {
// contains filtered or unexported fields
}
ProcessKill represents the COM_PROCESS_KILL command.
https://dev.mysql.com/doc/internals/en/com-process-kill.html https://mariadb.com/kb/en/com_process_kill/
COM_PROCESS_KILL asks the server to terminate a connection. COM_PROCESS_KILL is deprecated as of MySQL 5.7.11.
func (*ProcessKill) Bytes ¶
func (p *ProcessKill) Bytes() []byte
Bytes returns the packet as raw bytes.
func (*ProcessKill) ProcessID ¶
func (p *ProcessKill) ProcessID() uint32
ProcessID returns the process ID of a connection.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query represents the COM_QUERY command.
https://dev.mysql.com/doc/internals/en/com-query.html https://mariadb.com/kb/en/com_query/
type Quit ¶
type Quit struct {
// contains filtered or unexported fields
}
Quit represents the COM_QUIT command.
https://dev.mysql.com/doc/internals/en/com-quit.html https://mariadb.com/kb/en/com_quit/
type Refresh ¶
type Refresh struct {
// contains filtered or unexported fields
}
Refresh represents the COM_REFRESH command.
https://dev.mysql.com/doc/internals/en/com-refresh.html
COM_REFRESH calls REFRESH or FLUSH statements. COM_REFRESH is deprecated as of MySQL 5.7.11.
func (*Refresh) Subcommand ¶
Subcommand returns the string representation of the subcommand.
type ShutDown ¶
type ShutDown struct {
// contains filtered or unexported fields
}
ShutDown represents the COM_SHUTDOWN command.
https://dev.mysql.com/doc/internals/en/com-shutdown.html https://mariadb.com/kb/en/com_shutdown/
COM_SHUTDOWN is used to shut down the MySQL server. COM_SHUTDOWN requires SHUTDOWN privileges. COM_SHUTDOWN is deprecated as of MySQL 5.7.9.
type StatementBulkExecutePacket ¶
type StatementBulkExecutePacket struct {
// contains filtered or unexported fields
}
StatementBulkExecutePacket represents the COM_STMT_BULK_EXECUTE command.
https://mariadb.com/kb/en/com_stmt_bulk_execute/
COM_STMT_BULK_EXECUTE executes a bulk insert of a previously prepared statement.
func (*StatementBulkExecutePacket) Parameters ¶
func (p *StatementBulkExecutePacket) Parameters(definitions []mysql.Field) (parameters []interface{}, ok bool)
Parameters returns a slice of parameters.
func (*StatementBulkExecutePacket) StatementID ¶
func (p *StatementBulkExecutePacket) StatementID() uint32
StatementID returns the statement ID.
type StatementClosePacket ¶
type StatementClosePacket struct {
// contains filtered or unexported fields
}
StatementClosePacket represents the COM_STMT_CLOSE command.
https://dev.mysql.com/doc/internals/en/com-stmt-close.html https://mariadb.com/kb/en/3-binary-protocol-prepared-statements-com_stmt_close/
COM_STMT_CLOSE deallocates a prepared statement.
func (*StatementClosePacket) StatementID ¶
func (p *StatementClosePacket) StatementID() uint32
StatementID returns the statement ID.
type StatementExecutePacket ¶
type StatementExecutePacket struct {
// contains filtered or unexported fields
}
StatementExecutePacket represents the COM_STMT_EXECUTE command.
https://dev.mysql.com/doc/internals/en/com-stmt-execute.html https://mariadb.com/kb/en/com_stmt_execute/
COM_STMT_EXECUTE asks the server to execute a prepared statement, with the types and values for the placeholders.
Statement ID "-1" (0xffffffff) can be used to indicate the last statement prepared on current connection, for MariaDB server version 10.2 and above.
func (*StatementExecutePacket) Parameters ¶
func (p *StatementExecutePacket) Parameters(definitions []mysql.Field) (parameters []interface{}, ok bool)
Parameters returns a slice of parameters.
func (*StatementExecutePacket) StatementID ¶
func (p *StatementExecutePacket) StatementID() uint32
StatementID returns the statement ID.
type StatementFetchPacket ¶
type StatementFetchPacket struct {
// contains filtered or unexported fields
}
StatementFetchPacket represents the COM_STMT_FETCH command.
https://dev.mysql.com/doc/internals/en/com-stmt-fetch.html https://mariadb.com/kb/en/com_stmt_fetch/
COM_STMT_FETCH fetch rows from a existing resultset after a COM_STMT_EXECUTE.
func (*StatementFetchPacket) RowsCount ¶
func (s *StatementFetchPacket) RowsCount() uint32
RowsCount returns number of rows to fetch.
func (*StatementFetchPacket) StatementID ¶
func (p *StatementFetchPacket) StatementID() uint32
StatementID returns the statement ID.
type StatementPreparePacket ¶
type StatementPreparePacket struct {
// contains filtered or unexported fields
}
StatementPreparePacket represents the COM_STMT_PREPARE command.
https://dev.mysql.com/doc/internals/en/com-stmt-prepare.html https://mariadb.com/kb/en/com_stmt_prepare/
COM_STMT_PREPARE creates a prepared statement from passed query string. Parameter placeholders are marked with "?" in the query. A COM_STMT_PREPARE response is expected from the server after sending this command.
func (*StatementPreparePacket) Bytes ¶
func (p *StatementPreparePacket) Bytes() []byte
Bytes returns the packet as raw bytes.
func (*StatementPreparePacket) Query ¶
func (p *StatementPreparePacket) Query() string
Query returns the query text.
type StatementResetPacket ¶
type StatementResetPacket struct {
// contains filtered or unexported fields
}
StatementResetPacket represents the COM_STMT_RESET command.
https://dev.mysql.com/doc/internals/en/com-stmt-reset.html https://mariadb.com/kb/en/com_stmt_reset/
COM_STMT_RESET resets the data of a prepared statement which was accumulated with COM_STMT_SEND_LONG_DATA.
func (*StatementResetPacket) StatementID ¶
func (p *StatementResetPacket) StatementID() uint32
StatementID returns the statement ID.
type StatementSendLongDataPacket ¶
type StatementSendLongDataPacket struct {
// contains filtered or unexported fields
}
StatementSendLongDataPacket represents the COM_STMT_SEND_LONG_DATA command.
https://dev.mysql.com/doc/internals/en/com-stmt-send-long-data.html https://mariadb.com/kb/en/com_stmt_send_long_data/
COM_STMT_SEND_LONG_DATA is used to send byte stream data to the server, and the server appends this data to the specified parameter upon receiving it. It is usually used for big blobs.
func (*StatementSendLongDataPacket) Data ¶
func (p *StatementSendLongDataPacket) Data() []byte
Data returns the data in bytes.
func (*StatementSendLongDataPacket) ParameterID ¶
func (p *StatementSendLongDataPacket) ParameterID() uint16
ParameterID returns the parameter ID.
func (*StatementSendLongDataPacket) StatementID ¶
func (p *StatementSendLongDataPacket) StatementID() uint32
StatementID returns the statement ID.