Coming from mysqlclient or PyMySQL¶
Most code runs unchanged: connect() takes the same arguments in the same
positional order, with passwd and db as aliases, and cursorclass,
DictCursor, SSCursor, conv= and rustmy.constants are where code
written for MySQLdb or PyMySQL expects them.
What differs, on purpose¶
Each difference is pinned by a test.
- Invalid dates such as
0000-00-00come back asNone(as mysqlclient; PyMySQL returns the text). rowcountis-1while a streamed result is unread (as mysqlclient).lastrowidisNoneafter a statement that returns rows (PEP 249).- Closing a connection twice raises
InterfaceError(PEP 249). - Text a connection's character set cannot represent raises
DataErrorbefore anything is sent, instead ofUnicodeEncodeErroror a corrupted value. - Server errors are classed by SQLSTATE, so for example "unknown column"
(1054) is a
ProgrammingError, as the SQL standard defines it. One exception keeps code written for mysqlclient working: a numeric value out of range (1690) raisesrustmy.err.OutOfRangeError, both aDataError(its SQLSTATE) and anOperationalError(as mysqlclient raises it). bytesparameters go as_binary'…', so the server reads them as binary whatever the connection's character set;binary_prefix=Falsewrites the plain'…'of mysqlclient and PyMySQL.multi_statementsis off unless you ask for it, which keeps an injection from adding statements of its own.executemanyof anything butINSERT … VALUESsends its statements in windows of up to 256 before reading the replies, so after an error the rest of the failing statement's window has already run (see Many rows at once;cursor.max_pipeline = 1sends them one by one, as both drivers do).LOAD DATA LOCAL INFILEneedslocal_infile_dir:local_infile=Truealone, which lets mysqlclient and PyMySQL send any file the server asks for, raisesValueError(see Loading local files).
What you gain¶
- Wheels with nothing else to install, where mysqlclient needs libmysqlclient,
its headers,
pkg-configand a compiler. - Prepared statements, asyncio and connection pools, which neither has.
- Pipelined
executemanyforUPDATEandDELETE. - See Performance for the speed.