The old commands are supported for all MySQL Server versions from 3.20 upwards (and perhaps older).
change the default schema of the connection
1 [02] COM_INIT_DB string[EOF] schema name
command
(1)
-- 0x02
COM_INIT_DB
schema_name (string.EOF) -- name of the schema to change to
05 00 00 00 02 74 65 73 74 .....test
New in 3.20
A COM_QUERY is used to send the server a text-based query that is executed immediately.
The server replies to a COM_QUERY packet with a COM_QUERY Response.
The length of the query-string is a taken from the packet length - 1.
1 [03] COM_QUERY string[EOF] the query the server shall execute
command_id
(1)
-- 0x03
COM_QUERY
query (string.EOF) -- query_text
21 00 00 00 03 73 65 6c 65 63 74 20 40 40 76 65 !....select @@ve 72 73 69 6f 6e 5f 63 6f 6d 6d 65 6e 74 20 6c 69 rsion_comment li 6d 69 74 20 31 mit 1
New in 3.20
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
payload
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.

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 defintions part starts with a packet containing the column-count, followed by as many Column Definition packets as we have columns and terminated by an EOF packet.
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.
a packet containing a
Protocol::LengthEncodedInteger
column_count
column_count *
Protocol::ColumnDefinition
packets
one or more
ProtocolText::ResultsetRow
packets, each containing
column_count values
If the
SERVER_MORE_RESULTS_EXISTS
flag is set in the last
EOF_Packet
another ProtocolText::Resultset will follow (see
Multi-resultset).

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
}
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 - 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
}
sql/protocol.cc Protocol::send_result_set_metadata()
A row with the data for each column.
NULL is sent as
0xfb
everything else is converted into a string and
is sent as
Protocol::LengthEncodedString.
If the client wants to LOAD DATA from a LOCAL file into the server it sends:
LOAD DATA LOCAL INFILE '<filename>' INTO TABLE <table>;
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.
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
The response to a COM_FIELD_LIST can either be a
a
ERR_Packet
or
one or more Column
Definition packets and a closing
EOF_Packet
31 00 00 01 03 64 65 66 04 74 65 73 74 09 66 69 1....def.test.fi 65 6c 64 6c 69 73 74 09 66 69 65 6c 64 6c 69 73 eldlist.fieldlis 74 02 69 64 02 69 64 0c 3f 00 0b 00 00 00 03 00 t.id.id.?....... 00 00 00 00 fb 05 00 00 02 fe 00 00 02 00 ..............
a low-level version of several FLUSH ... and RESET ... commands.
call REFRESH or FLUSH statements
1 [07] COM_REFRESH 1 flags
command
(1)
-- 0x07
COM_REFRESH
sub_command (1) -- a bitmask of sub-systems to refresh
sub_command |
constant name |
description |
|---|---|---|
0x01 |
REFRESH_GRANT |
Refresh grant tables FLUSH PRIVILEGES |
0x02 |
REFRESH_LOG |
Start on new log file FLUSH LOGS |
0x04 |
REFRESH_TABLES |
close all tables FLUSH TABLES |
0x08 |
REFRESH_HOSTS |
Flush host cache FLUSH HOSTS |
0x10 |
REFRESH_STATUS |
Flush status variables FLUSH STATUS |
0x20 |
REFRESH_THREADS |
Flush thread cache |
0x40 |
REFRESH_SLAVE |
Reset master info and restart slave thread RESET SLAVE |
0x80 |
REFRESH_MASTER |
Remove all bin logs in the index and truncate the index RESET MASTER |
New in 3.20
COM_SHUTDOWN is used to shutdown the mysql-server.
SHUTDOWN privilege is required.
shutdown the server
1 [08] COM_SHUTDOWN
if shutdown type != 0x00 {
1 shutdown type
}
command
(1)
-- 0x08
COM_SHUTDOWN
sub_command
(1)
-- optional if sub_command is
0x00
type |
constant name |
description |
|---|---|---|
0x00 |
SHUTDOWN_DEFAULT |
defaults to SHUTDOWN_WAIT_ALL_BUFFERS |
0x01 |
SHUTDOWN_WAIT_CONNECTIONS |
wait for existing connections to finish |
0x02 |
SHUTDOWN_WAIT_TRANSACTIONS |
wait for existing trans to finish |
0x08 |
SHUTDOWN_WAIT_UPDATES |
wait for existing updates to finish (=> no partial MyISAM update) |
0x10 |
SHUTDOWN_WAIT_ALL_BUFFERS |
flush InnoDB buffers and other storage engines' buffers |
0x11 |
SHUTDOWN_WAIT_CRITICAL_BUFFERS |
don't flush InnoDB buffers, flush other storage engines' buffers |
0xfe |
KILL_QUERY |
|
0xff |
KILL_CONNECTION |
New in 3.20
Even if several shutdown types are defined, right now only one is in use: SHUTDOWN_WAIT_ALL_BUFFERS
Get a human readable string of internal statistics.
Same as KILL <id>.
COM_DEBUG triggers a dump on internal debug info to stdout of the mysql-server.
The SUPER privilege is required for this operation.
dump debug info to stdout
EOF_Packet
or
ERR_Packet
on error
1 [0d] COM_DEBUG
New in 3.21
COM_CHANGE_USER changes the user of the current connection and reset the connection state.
user variables
temp tables
prepared statemants
... and others
It is followed by the same states as the initial handshake.
change the user of the current connection
1 [11] COM_CHANGE_USER
string[NUL] user
if capabilities & SECURE_CONNECTION {
1 auth-response-len
string[$len] auth-response
} else {
string[NUL] auth-response
}
string[NUL] schema-name
if more data {
2 character-set (since 5.1.23?)
}
if more data {
string[NUL] auth plugin name (since WL1054 and if CLIENT_PLUGIN_AUTH is used)
}
New in 3.23
character set is the connection
character set as defined in
Protocol::CharacterSet
and is also the encoding of user and
schema-name.
