All pages
Powered by GitBook
1 of 17

2 - Text Protocol

Text protocol commands are sent from client to server. The text protocol has a less comprehensive format than the binary protocol, which is used by prepared statements only

COM_CHANGE_USER

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.

Fields

  • 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

  • if (server_capabilities & CLIENT_CONNECT_ATTRS)

    • int size of connection attributes

    • loop:

      • string key

      • string value

Response

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.

This page is licensed: CC BY-SA / Gnu FDL

COM_CREATE_DB

Warning: This command is deprecated and not used by MariaDB connectors any more. Please use the SQL statements CREATE SCHEMA or CREATE DATABASE instead.

This page is licensed: CC BY-SA / Gnu FDL

COM_DEBUG

The COM_DEBUG command forces the server to dump debug information to stdout. It requires super privileges.

Fields

  • int<1> 0xOD : COM_DEBUG Header

Response

EOF Packet

This page is licensed: CC BY-SA / Gnu FDL

COM_DROP_DB

Warning: This command is deprecated and not used by MariaDB connectors any more. Please use the SQL statements DROP SCHEMA or DROP DATABASE instead.

This page is licensed: CC BY-SA / Gnu FDL

COM_FIELD_LIST

Warning: This command is deprecated and not used by MariaDB connectors any more. Please use the SQL statements SHOW COLUMNS or SELECT FROM INFORMATION_SCHEMA.COLUMNS instead.

Fields

  • int<1> 0x04 : COM_FIELD_LIST Header

Response

  • n resultset row

  • EOF_Packet

This page is licensed: CC BY-SA / Gnu FDL

COM_INIT_DB

COM_INIT_DB is used to specify the default schema for the connection.

Fields

  • int<1> 0x02 : COM_INIT_DB Header

  • string schema name

Response

ERR_Packet or OK_Packet

Example

06 00 00 00 02 74 65 73 74 63                    .....testc

This page is licensed: CC BY-SA / Gnu FDL

COM_PING

COM_PING permits sending a packet containing one byte to check that the connection is active.

Fields

  • int<1> 0x0e : COM_PING Header

Response

OK_Packet

This page is licensed: CC BY-SA / Gnu FDL

COM_PROCESS_KILL

Forces the server to terminate a specified connection.

Fields

  • int<1> 0xC COM_PROCESS_KILL

  • int<4> process id

Response

OK Packet or ERR Packet

This page is licensed: CC BY-SA / Gnu FDL

COM_PROCESSLIST

Warning: This command is deprecated and not used by MariaDB connectors any more. Please use the SQL statement SHOW PROCESSLIST instead.

This page is licensed: CC BY-SA / Gnu FDL

COM_QUERY

With the COM_QUERY command, the client sends the server an SQL statement to be executed immediately.

Fields

  • int<1> 0x03 : COM_QUERY header

  • string SQL statement

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 NO_BACKSLASH_ESCAPES bit set then the escape character is a single quote(' = 0x60)

If the escape character is a backslash, the following characters are escaped:

  • single quote (' = 0x60)

  • back slash (\ = 0x5c)

  • double quote (" = 0x22)

  • null character (0x00)

If the escape character is a single quote, only the single quote (' = 0x60) can be escaped.

Response

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 resultset.

  • 0xFB - LOCAL_INFILE Packet if the query was "LOCAL INFILE ...".

  • Or a Resultset, when the query returns results (in case of a SELECT query for example).

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

COM_QUIT

Using the COM_QUIT command, the client tells the server that the connection should be terminated.

Fields

  • int<1> 0x01 : COM_QUIT Header

Response

Server terminates connection.

This page is licensed: CC BY-SA / Gnu FDL

COM_RESET_CONNECTION

COM_RESET_CONNECTION Resets a connection without re-authentication.

This will :

  • rollback any open transaction

  • reset transaction isolation level

  • reset session variables

  • delete user variables

  • remove temporary tables

  • remove all PREPARE statement

Database will NOT be reset to initial value.

Fields

  • int<1> 0x1f : COM_RESET_CONNECTION Header

Response

ERR_Packet or OK_Packet

This page is licensed: CC BY-SA / Gnu FDL

COM_SET_OPTION

Enables or disables server option.

Fields

  • int<1> 0x1B COM_SET_OPTION

  • int<2> option

Options

Constant

Value

MYSQL_OPTION_MULTI_STATEMENTS_ON

0

MYSQL_OPTION_MULTI_STATEMENTS_OFF

1

Response

EOF Packet on success or ERR packet.

This page is licensed: CC BY-SA / Gnu FDL

COM_SHUTDOWN

Shuts down the server. To execute this command the SHUTDOWN privilege is required.

Fields

  • int<1> 0x0A COM_SHUTDOWN

  • int<1> option

Options

Constant

Value

SHUTDOWN_DEFAULT

0

Response

OK Packet or ERR packet.

This page is licensed: CC BY-SA / Gnu FDL

COM_SLEEP

This command is used inside the server only.

Direction

used inside server only

Fields

  • int<1> 0x00 : COM_SLEEP header

Response

ERR_Packet

This page is licensed: CC BY-SA / Gnu FDL

COM_STATISTICS

Get internal server statistics.

Fields

  • int<1> 0x09 : COM_STATISTICS Header

Response

string Human readable string

This page is licensed: CC BY-SA / Gnu FDL