Functionality Added or Changed
The original message passed to
was not saved in such a way that it could be retrieved. Instead,
Error.msg attribute was formatted with
the error number and SQLSTATE value. Now only the original
message is saved in the
The formatted value together with the error number and SQLSTATE
value can be obtained by printing or getting the string
representation of the error object. Example:
try: conn = mysql.connector.connect(database = "baddb") except mysql.connector.Error as e: print "Error code:", e.errno # error number print "SQLSTATE value:", e.sqlstate # SQLSTATE value print "Error message:", e.msg # error message print "Error:", e # errno, sqlstate, msg values s = str(e) print "Error:", s # errno, sqlstate, msg values
Output for individual unit tests did not show timings, making it
more difficult to debug problems that involve a change in test
execution time. unittest.py now has a new
--stats option that runs tests and shows
elapsed time for each.
It is also possible to save the data to a MySQL server. When the
--stats-host option is given with other options
--stats-user, results are saved to a
myconnpy_X_Y_Z. The table
contains the name of the test case and columns that combine
Python and MySQL versions; for example, py27my55 or py33my56.
For example, to see the difference between MySQL 5.1 and 5.6, using Python 2.7, after running the test cases for both using Connector/Python 1.1.0, use this statement:
SELECT test_case, py27my51, py27my56, (py27my56-py27my51) AS diff51 FROM myconnpy_1_1_0 WHERE (py27my56-py27my51) > 0.5;
MySQL Connector/Python now supports simple connection pooling that has these characteristics:
A pool opens a number of connections and handles thread safety when providing connections to requesters.
The size of a connection pool is configurable at pool creation time. It cannot be resized thereafter.
A connection pool can be named at pool creation time. If no name is given, one is generated using the connection parameters.
The connection pool name can be retrieved from the connection pool or connections obtained from it.
It is possible to have multiple connection pools. This enables applications to support pools of connections to different MySQL servers, for example.
For each connection request, the pool provides the next available connection. No round-robin or other scheduling algorithm is used.
It is possible to reconfigure the connection parameters used
by a pool. These apply to connections obtained from the pool
thereafter. Reconfiguring individual connections obtained
from the pool by calling the connection
config() method is not supported.
Applications that can benefit from connection-pooling capability include:
Middleware that maintains multiple connections to multiple MySQL servers and requires connections to be readily available.
Web sites that can have more “permanent” connections open to the MySQL server.
The connection pooling implementation involves these interface elements:
A new module,
provides two classes:
instantiates and manages connection pools, and
PooledMySQLConnection is similar to
MySQLConnection but is used for
connections that are part of a connection pool.
A new exception,
PoolError, occurs for
PoolError is a
For more information, see Connector/Python Connection Pooling.
Connector/Python now includes a
mysql.connector.django module that provides a
Django backend for MySQL. This backend supports new features
found in MySQL 5.6 such as fractional seconds support for
temporal data types. For more information, see
Connector/Python Django Backend.
fetchmany(), the result returned by
fetchall() was missing one row.
Previously, executing a statement after the connection was
closed raised an
OperationalError with an
unclear error. Connector/Python now returns the client error
MySQL Server has gone away, with an
Error() class has been extended to accept
a new argument,
extra_msg. When given, it is
appended between brackets. For example:
MySQL Error (Some extra message)
LOAD DATA LOCAL INFILE failed for files
approximately 14MB or larger.
InternalError was raised during
transaction rollback if there were unread results. The
MySQLConnection.rollback() method now
consumes unread results instead of raising an error.
Python 2.6 and 2.7 raised a
unicode_literals was used and a database name
contained nonlatin Unicode characters.
executemany() without any data
ProgrammingError rather than doing
OperationalError was raised if a
cursor object was closed while there were unread results.
Connector/Python now raises an
indicating that there are still unread results. This provides
information that to avoid the error it is necessary to consume
the result by reading all rows.
(Bug #67649, Bug #17041240)
MySQLCursor.executemany() method raised
an exception when a SQL function was used as a column value when
(Bug #69675, Bug #17065366)