Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sql.mysql.protocol

import sql.mysql.protocol

sql lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled sql.mysql.protocol.* needs import sql.mysql.protocol.

The MySQL client/server protocol: the handshake that opens a connection and the command exchange that runs everything after it.

A connection is strictly one command at a time. The client sends a command packet, the server answers with one of three shapes, and nothing else may be sent until that answer is complete:

AnswerShape
OKThe command did something and returned no rows.
ERRThe command failed, with a number and a SQLSTATE.
A result setA column count, the columns, then the rows.

Why the end of a result set is awkward

A row and the marker that ends the rows are told apart by their first byte, and 0xfe means both “the rows are over” and “a length encoded integer of eight bytes follows”. The length decides: a genuine end marker is short, and a row that happens to start 0xfe is not. Servers that negotiate CLIENT_DEPRECATE_EOF send an OK packet there instead, which is what this adapter asks for, but the ambiguity has to be handled anyway for the ones that do not.

Constants

CAPABILITIES

sql.mysql.CAPABILITIES = {...}

What the client asks for and what the server offers.

STATUS

sql.mysql.protocol.STATUS = {...}

What the server says about the session after each command.

COMMANDS

sql.mysql.COMMANDS = {...}

The commands this adapter sends.

CURSOR_READ_ONLY

sql.mysql.protocol.CURSOR_READ_ONLY = 1

Asks the server to keep the result open rather than send it all.

CURSOR_NONE

sql.mysql.protocol.CURSOR_NONE = 0

No cursor: the whole result comes back at once.


2026, Richard Ore and Zuri contributors