Payload of OK Packet
Type | Name | Description |
---|---|---|
int<1> | header | [00] or [fe] the OK packet header |
int<lenenc> | affected_rows | affected rows |
int<lenenc> | last_insert_id | last insert-id |
if capabilities & CLIENT_PROTOCOL_41 { | ||
int<2> | status_flags | Status Flags |
int<2> | warnings | number of warnings |
} elseif capabilities & CLIENT_TRANSACTIONS { | ||
int<2> | status_flags | Status Flags |
} | ||
if capabilities & CLIENT_SESSION_TRACK { | ||
string<lenenc> | info | human readable status information |
if status_flags & SERVER_SESSION_STATE_CHANGED { | ||
string<lenenc> | session_state_changes | session state info |
} | ||
} else { | ||
string<EOF> | info | human readable status information |
} |
对于执行成功的命令,通常会返回OK报文
OK报文和EOF报文的区别
对于OK报文和EOF报文,其header字段都可能为0xfe,那么有如下规则来区分这两种报文
OK Packet:length of packet > 7
EOF Packet:length of packet < 9
eg:
OK with CLIENT_PROTOCOL_41. 0 affected rows, last-insert-id was 0, AUTOCOMMIT enabled, 0 warnings. No further info.
Status Flags说明:
Flag | Value | Comment |
---|---|---|
SERVER_STATUS_IN_TRANS | 0x0001 | a transaction is active |
SERVER_STATUS_AUTOCOMMIT | 0x0002 | auto-commit is enabled |
SERVER_MORE_RESULTS_EXISTS | 0x0008 |
|
SERVER_STATUS_NO_GOOD_INDEX_USED | 0x0010 |
|
SERVER_STATUS_NO_INDEX_USED | 0x0020 |
|
SERVER_STATUS_CURSOR_EXISTS | 0x0040 | Used by Binary Protocol Resultset to signal thatCOM_STMT_FETCH must be used to fetch the row-data. |
SERVER_STATUS_LAST_ROW_SENT | 0x0080 |
|
SERVER_STATUS_DB_DROPPED | 0x0100 |
|
SERVER_STATUS_NO_BACKSLASH_ESCAPES | 0x0200 |
|
SERVER_STATUS_METADATA_CHANGED | 0x0400 |
|
SERVER_QUERY_WAS_SLOW | 0x0800 |
|
SERVER_PS_OUT_PARAMS | 0x1000 |
|
SERVER_STATUS_IN_TRANS_READONLY | 0x2000 | in a read-only transaction |
SERVER_SESSION_STATE_CHANGED | 0x4000 | connection state information has changed |
Session State Information
该部分信息由以下部分组成:
Type | Name | Description |
---|---|---|
int<1> | type | type of data |
string<lenenc> | data | data of the changed session info |
其中type有3种,分别是:
types of State Change Information
Name | Value | Description |
---|---|---|
SESSION_TRACK_SYSTEM_VARIABLES | 0x00 | one or more system variables changed. See also:session_track_system_variables |
SESSION_TRACK_SCHEMA | 0x01 | schema changed. See also: session_track_schema |
SESSION_TRACK_STATE_CHANGE | 0x02 | "track state change" changed. See also:session_track_state_change |
不同type类型对应的data组成是不同的
SESSION_TRACK_SYSTEM_VARIABLES 对应的data字段内容
Type | Name | Description |
---|---|---|
string<lenenc> | name | name of the changed system variable |
string<lenenc> | value | value of the changed system variable |
eg:
SET autocommit = OFF
00 0f 0a 61 75 74 6f 63 6f 6d 6d 69 7403 4f 46 46 | ....autocommit.OFF |
SESSION_TRACK_SCHEMA 对应的data字段内容
Type | Name | Description |
---|---|---|
string<lenenc> | name | name of the changed schema |
eg:
USE test
01 05 04 74 65 73 74 | ...test |
SESSION_TRACK_STATE_CHANGE 对应的data字段内容
备注:A flag byte that indicates whether session state changes occurred. This flag is represented as an ASCII value
Type | Name | Description |
---|---|---|
string<lenenc> | is_tracked | [31] ("1") if state tracking got enabled. |