Documentation Home
MySQL Internals Manual
Download this Manual
EPUB - 0.8Mb

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 TypeHex ValueNotes
Protocol::MYSQL_TYPE_DECIMAL0x00Implemented by ProtocolBinary::MYSQL_TYPE_DECIMAL
Protocol::MYSQL_TYPE_TINY0x01Implemented by ProtocolBinary::MYSQL_TYPE_TINY
Protocol::MYSQL_TYPE_SHORT0x02Implemented by ProtocolBinary::MYSQL_TYPE_SHORT
Protocol::MYSQL_TYPE_LONG0x03Implemented by ProtocolBinary::MYSQL_TYPE_LONG
Protocol::MYSQL_TYPE_FLOAT0x04Implemented by ProtocolBinary::MYSQL_TYPE_FLOAT
Protocol::MYSQL_TYPE_DOUBLE0x05Implemented by ProtocolBinary::MYSQL_TYPE_DOUBLE
Protocol::MYSQL_TYPE_NULL0x06Implemented by ProtocolBinary::MYSQL_TYPE_NULL
Protocol::MYSQL_TYPE_TIMESTAMP0x07Implemented by ProtocolBinary::MYSQL_TYPE_TIMESTAMP
Protocol::MYSQL_TYPE_LONGLONG0x08Implemented by ProtocolBinary::MYSQL_TYPE_LONGLONG
Protocol::MYSQL_TYPE_INT240x09Implemented by ProtocolBinary::MYSQL_TYPE_INT24
Protocol::MYSQL_TYPE_DATE0x0aImplemented by ProtocolBinary::MYSQL_TYPE_DATE
Protocol::MYSQL_TYPE_TIME0x0bImplemented by ProtocolBinary::MYSQL_TYPE_TIME
Protocol::MYSQL_TYPE_DATETIME0x0cImplemented by ProtocolBinary::MYSQL_TYPE_DATETIME
Protocol::MYSQL_TYPE_YEAR0x0dImplemented by ProtocolBinary::MYSQL_TYPE_YEAR
Protocol::MYSQL_TYPE_NEWDATE [a]0x0esee Protocol::MYSQL_TYPE_DATE
Protocol::MYSQL_TYPE_VARCHAR0x0fImplemented by ProtocolBinary::MYSQL_TYPE_VARCHAR
Protocol::MYSQL_TYPE_BIT0x10Implemented by ProtocolBinary::MYSQL_TYPE_BIT
Protocol::MYSQL_TYPE_TIME2 [a]0x13see Protocol::MYSQL_TYPE_TIME
Protocol::MYSQL_TYPE_NEWDECIMAL0xf6Implemented by ProtocolBinary::MYSQL_TYPE_NEWDECIMAL
Protocol::MYSQL_TYPE_ENUM0xf7Implemented by ProtocolBinary::MYSQL_TYPE_ENUM
Protocol::MYSQL_TYPE_SET0xf8Implemented by ProtocolBinary::MYSQL_TYPE_SET
Protocol::MYSQL_TYPE_TINY_BLOB0xf9Implemented by ProtocolBinary::MYSQL_TYPE_TINY_BLOB
Protocol::MYSQL_TYPE_MEDIUM_BLOB0xfaImplemented by ProtocolBinary::MYSQL_TYPE_MEDIUM_BLOB
Protocol::MYSQL_TYPE_LONG_BLOB0xfbImplemented by ProtocolBinary::MYSQL_TYPE_LONG_BLOB
Protocol::MYSQL_TYPE_BLOB0xfcImplemented by ProtocolBinary::MYSQL_TYPE_BLOB
Protocol::MYSQL_TYPE_VAR_STRING0xfdImplemented by ProtocolBinary::MYSQL_TYPE_VAR_STRING
Protocol::MYSQL_TYPE_STRING0xfeImplemented by ProtocolBinary::MYSQL_TYPE_STRING

[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

Download this Manual
EPUB - 0.8Mb
User Comments
Sign Up Login You must be logged in to post a comment.