Documentation Home
MySQL Internals Manual

MySQL Internals Manual  /  ...  /  COM_QUERY Response COM_QUERY Response

The query-response packet is a meta packet which can be one of

The type of the packet is defined by the type-identifier:

COM_QUERY response
  response to a COM_QUERY packet

    lenenc-int     number of columns in the resultset

If the number of columns in the resultset is 0, this is a OK_Packet.

If it is not a valid Protocol::LengthEncodedInteger it is either a ERR_Packet or a Protocol::LOCAL_INFILE_Request. Text Resultset

A Text Resultset is a possible COM_QUERY Response.

It is made up of two parts:

  • the column definitions

  • the rows

which consist of a sequence of packets.

The column definitions part starts with a packet containing the column-count, followed by as many Column Definition packets as there are columns and terminated by an EOF_Packet. packet if the CLIENT_DEPRECATE_EOF capability flag is not set.

Each row is a packet, too. The rows are terminated by another EOF_Packet. In case the query could generate the column-definition, but generating the rows afterwards failed, a ERR_Packet may be sent instead of the last EOF_Packet.


If the SERVER_MORE_RESULTS_EXISTS flag is set in the last EOF_Packet or (if the CLIENT_DEPRECATE_EOF capability flag is set) OK_Packet, another ProtocolText::Resultset will follow (see Multi-resultset). Column Type

Table 14.4 Column Types

Table Column Type Hex Value Notes
Protocol::MYSQL_TYPE_DECIMAL 0x00 Implemented by ProtocolBinary::MYSQL_TYPE_DECIMAL
Protocol::MYSQL_TYPE_TINY 0x01 Implemented by ProtocolBinary::MYSQL_TYPE_TINY
Protocol::MYSQL_TYPE_SHORT 0x02 Implemented by ProtocolBinary::MYSQL_TYPE_SHORT
Protocol::MYSQL_TYPE_LONG 0x03 Implemented by ProtocolBinary::MYSQL_TYPE_LONG
Protocol::MYSQL_TYPE_FLOAT 0x04 Implemented by ProtocolBinary::MYSQL_TYPE_FLOAT
Protocol::MYSQL_TYPE_DOUBLE 0x05 Implemented by ProtocolBinary::MYSQL_TYPE_DOUBLE
Protocol::MYSQL_TYPE_NULL 0x06 Implemented by ProtocolBinary::MYSQL_TYPE_NULL
Protocol::MYSQL_TYPE_TIMESTAMP 0x07 Implemented by ProtocolBinary::MYSQL_TYPE_TIMESTAMP
Protocol::MYSQL_TYPE_LONGLONG 0x08 Implemented by ProtocolBinary::MYSQL_TYPE_LONGLONG
Protocol::MYSQL_TYPE_INT24 0x09 Implemented by ProtocolBinary::MYSQL_TYPE_INT24
Protocol::MYSQL_TYPE_DATE 0x0a Implemented by ProtocolBinary::MYSQL_TYPE_DATE
Protocol::MYSQL_TYPE_TIME 0x0b Implemented by ProtocolBinary::MYSQL_TYPE_TIME
Protocol::MYSQL_TYPE_DATETIME 0x0c Implemented by ProtocolBinary::MYSQL_TYPE_DATETIME
Protocol::MYSQL_TYPE_YEAR 0x0d Implemented by ProtocolBinary::MYSQL_TYPE_YEAR
Protocol::MYSQL_TYPE_NEWDATE [a] 0x0e see Protocol::MYSQL_TYPE_DATE
Protocol::MYSQL_TYPE_VARCHAR 0x0f Implemented by ProtocolBinary::MYSQL_TYPE_VARCHAR
Protocol::MYSQL_TYPE_BIT 0x10 Implemented by ProtocolBinary::MYSQL_TYPE_BIT
Protocol::MYSQL_TYPE_DATETIME2 [a] 0x12 see Protocol::MYSQL_TYPE_DATETIME
Protocol::MYSQL_TYPE_TIME2 [a] 0x13 see Protocol::MYSQL_TYPE_TIME
Protocol::MYSQL_TYPE_NEWDECIMAL 0xf6 Implemented by ProtocolBinary::MYSQL_TYPE_NEWDECIMAL
Protocol::MYSQL_TYPE_ENUM 0xf7 Implemented by ProtocolBinary::MYSQL_TYPE_ENUM
Protocol::MYSQL_TYPE_SET 0xf8 Implemented by ProtocolBinary::MYSQL_TYPE_SET
Protocol::MYSQL_TYPE_TINY_BLOB 0xf9 Implemented by ProtocolBinary::MYSQL_TYPE_TINY_BLOB
Protocol::MYSQL_TYPE_MEDIUM_BLOB 0xfa Implemented by ProtocolBinary::MYSQL_TYPE_MEDIUM_BLOB
Protocol::MYSQL_TYPE_LONG_BLOB 0xfb Implemented by ProtocolBinary::MYSQL_TYPE_LONG_BLOB
Protocol::MYSQL_TYPE_BLOB 0xfc Implemented by ProtocolBinary::MYSQL_TYPE_BLOB
Protocol::MYSQL_TYPE_VAR_STRING 0xfd Implemented by ProtocolBinary::MYSQL_TYPE_VAR_STRING
Protocol::MYSQL_TYPE_STRING 0xfe Implemented by ProtocolBinary::MYSQL_TYPE_STRING
Protocol::MYSQL_TYPE_GEOMETRY 0xff  

[a] Internal to MySQL Server. Not used in ProtocolBinary::* nor ProtocolText::*.


Not all Table Column Types have a representation in the Text or Binary protocol. While a TIMESTAMP field may be a MYSQL_TYPE_TIMESTAMP or MYSQL_TYPE_TIMESTAMP2 within the MySQL Server depending on the version, in the protocol it always is MYSQL_TYPE_TIMESTAMP. Column Definition

if CLIENT_PROTOCOL_41 is set Protocol::ColumnDefinition41 is used, Protocol::ColumnDefinition320 otherwise


Column Definition

lenenc_str     catalog
lenenc_str     schema
lenenc_str     table
lenenc_str     org_table
lenenc_str     name
lenenc_str     org_name
lenenc_int     length of fixed-length fields [0c]
2              character set
4              column length
1              type
2              flags
1              decimals
2              filler [00] [00]
  if command was COM_FIELD_LIST {
lenenc_int     length of default-values
string[$len]   default values
Implemented By


  • catalog (lenenc_str) -- catalog (always "def")

  • schema (lenenc_str) -- schema-name

  • table (lenenc_str) -- virtual table-name

  • org_table (lenenc_str) -- physical table-name

  • name (lenenc_str) -- virtual column name

  • org_name (lenenc_str) -- physical column name

  • next_length (lenenc_int) -- length of the following fields (always 0x0c)

  • character_set (2) -- is the column character set and is defined in Protocol::CharacterSet.

  • column_length (4) -- maximum length of the field

  • column_type (1) -- type of the column as defined in Column Type

  • flags (2) -- flags

  • decimals (1) -- max shown decimal digits

    • 0x00 for integers and static strings

    • 0x1f for dynamic strings, double, float

    • 0x00 to 0x51 for decimals


decimals and column_length can be used for text-output formatting.


Column Definition

lenenc-str     table
lenenc-str     name
lenenc_int     [03] length of the column_length field
3              column_length
lenenc_int     [01] length of type field
1              type
  if capabilities & CLIENT_LONG_FLAG {
lenenc_int     [03] length of flags+decimals fields
2              flags
1              decimals
  } else {
1              [02] length of flags+decimals fields
1              flags
1              decimals
  if command was COM_FIELD_LIST {
lenenc_int     length of default-values
string[$len]   default values
Implemented By

Protocol::send_result_set_metadata() Text Resultset Row

A row with the data for each column. LOCAL INFILE Request

If the client wants to LOAD DATA from a LOCAL file into the server it sends:


The LOCAL keyword triggers the server to send a LOCAL INFILE request packet which asks the client to send the file via a Protocol::LOCAL_INFILE_Data response.

The client has to set the CLIENT_LOCAL_FILES capability.



1              [fb] LOCAL INFILE
string[EOF]    filename the client shall send
0c 00 00 01 fb 2f 65 74    63 2f 70 61 73 73 77 64    ...../etc/passwd LOCAL INFILE Data

If the client has data to send, it sends in one or more non-empty packets AS IS followed by a empty packet.

If the file is empty or there is a error while reading the file only the empty packet is sent.

string[EOF]             the filedata

data (string.EOF) -- the raw file data

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
  Posted by Bill Adams on April 27, 2017
For those like me who captured a query and response in tcpdump and viewed in Wireshark:

For an empty result set, I see only EOF marker packets right after the last Column Definition packet:

MySQL Protocol
Packet Length: 5
Packet Number: 4
EOF marker: 254
Warnings: 0
Server Status: 0x0002

In contrast, when results were returned, they appeared right before the final EOF packet. The text field is the value of the column requested:
MySQL Protocol
Packet Length: 7
Packet Number: 4
text: 670943