Understand the text protocol in the Server's client/server communication. This section details how SQL commands and results are exchanged as plain text, including command types and packet structures.
COM_CHANGE_USER
resets the connection and re-authenticates with the given credentials. The packet is identical to the authentication packet in the connection handshake.
int<1> 0x11
: COM_CHANGE_USER
header.
string username.
If (server_capabilities
& CLIENT_SECURE_CONNECTION
):
int<1> length of authentication response.
string authentication response.
Else:
string authentication response.
string default schema name.
int<2> client character collation.
If (server_capabilities
& CLIENT_PLUGIN_AUTH
):
string authentication plugin name.
Server response is like connection authentication :
An OK
packet in case of success OK_Packet.
An error packet in case of error ERR_Packet.
Authentication switch:
If the client or server doesn't have PLUGIN_AUTH
capability:
Server sends 0xFE
byte.
Client sends old_password
.
Else:
Server sends Authentication switch request.
Client may have many exchanges with the server according to the Plugin.
Authentication switch ends with server sending either OK_Packet or ERR_Packet.
If the authentication fails more than three times, all future COM_CHANGE_USER
commands on the connection will return the #08S01 Unknown command
error. This is an anti-brute-force mechanism designed to prevent rapid guessing of passwords.
This page is licensed: CC BY-SA / Gnu FDL
This page is licensed: CC BY-SA / Gnu FDL
This page is licensed: CC BY-SA / Gnu FDL
This page is licensed: CC BY-SA / Gnu FDL
COM_INIT_DB
is used to specify the default schema for the connection.
ERR_Packet or OK_Packet.
06 00 00 00 02 74 65 73 74 63 .....testc
This page is licensed: CC BY-SA / Gnu FDL
Forces the server to terminate a specified connection.
OK Packet or ERR Packet.
This page is licensed: CC BY-SA / Gnu FDL
This page is licensed: CC BY-SA / Gnu FDL
With the COM_QUERY
command, the client sends the server an SQL statement to be executed immediately.
The SQL statement should be properly escaped. The escape character is usually a backslash '' = 0x5c
. However, if the status flag returned by the last OK Packet had the NO_BACKSLASH_ESCAPES
bit set, the escape character is a single quote ('
= 0x60
).
If the escape character is a backslash, the following characters are escaped:
Single quote ('
= 0x60
).
Backslash (\
= 0x5c
).
Double quote ("
= 0x22
).
Null character (0x00
).
If the escape character is a single quote, only the single quote ('
= 0x60
) can be escaped.
The server can answer with 4 different responses that can be differentiated by the first byte (packet header):
0xFF
- ERR_Packet if any error occurs.
0x00
- OK_Packet when query execution works without result set.
0xFB
- LOCAL_INFILE Packet if the query was LOCAL INFILE ...
.
Or a result set, when the query returns results (in case of a SELECT
query, for example).
1b 00 00 00 03 44 52 4f 50 20 54 41 42 4c 45 20
.....DROP TABLE
49 46 20 45 58 49 53 54 53 20 62 75 6c 6b 31
IF EXISTS bulk1
This page is licensed: CC BY-SA / Gnu FDL
Using the COM_QUIT
command, the client tells the server that the connection should be terminated.
int<1> 0x01
: COM_QUIT
header.
Server terminates connection.
This page is licensed: CC BY-SA / Gnu FDL
COM_RESET_CONNECTION
resets a connection without reauthentication.
The command does this:
Roll back any open transactions.
Reset transaction isolation level.
Rset session variables.
Delete user variables.
Remove temporary tables.
Remove all PREPARE
statements.
Database will NOT
be reset to initial value.
int<1> 0x1f : COM_RESET_CONNECTION
Header
This page is licensed: CC BY-SA / Gnu FDL
Enables or disables server option.
MYSQL_OPTION_MULTI_STATEMENTS_ON
0
MYSQL_OPTION_MULTI_STATEMENTS_OFF
1
EOF Packet on success or ERR packet.
This page is licensed: CC BY-SA / Gnu FDL
Shuts down the server. To execute this command, the SHUTDOWN privilege is required.
Constant
Value
SHUTDOWN_DEFAULT
0
OK Packet or ERR packet.
This page is licensed: CC BY-SA / Gnu FDL
This command is used inside the server only.
Used inside server only.
int<1> 0x00
: COM_SLEEP
header.
This page is licensed: CC BY-SA / Gnu FDL