Functionality Added or Changed
Incompatible Change: Previous series of Connector/Python had separate Python 2 and Python 3 code bases. For Connector/Python 2.0, the source tree has been reorganized to have a single code base, for easier maintenance, testing, and distribution.
This reorganization results in an incompatible change in
behavior: With the use of “raw” cursors, the
returned values is of the
This is necessary for having both Python 2 and 3 return the same
data. Consider the following example:
import mysql.connector cnx = mysql.connector.connect(raw=True) cursor = cnx.cursor() cursor.execute('SELECT 1') print(cursor.fetchall())
In Connector/Python 1.x, the output is:
Using Python 2:
Using Python 3:
In Connector/Python 2.0, for both Python versions, the output
To get the same value as in Connector/Python 1.x, do this:
Using Python 2:
Using Python 3:
Previously, to enable use of
LOAD DATA LOCAL
INFILE, clients had to explicitly set the
ClientFlag.LOCAL_FILES flag. This flag is now
enabled by default. To disable it, the
allow_local_infile option for
connect()can be set to
For a stored procedure that produces multiple result sets, it is
now possible possible to execute the procedure and process its
results by executing a
statement. Execute the statement using
execute() with a
multi=True argument, and use the returned
iterator to process each result in turn.
(Bug #73291, Bug #19207922)
Connector/Python now supports option files using two new options
option_files: Which option files to read.
The value can be a file path name (a string) or a sequence
of path name strings. By default, Connector/Python reads no
option files, so this argument must be given explicitly to
cause option files to be read. Files are read in the order
option_groups: Which groups to read from
option files, if option files are read. The value can be an
option group name (a string) or a sequence of group name
strings. If this argument is not given, the default value is
['client, 'connector_python'] to read the
For more information, see Connector/Python Option-File Support.
mysql.connector.cursor module supports
four new cursor classes:
MySQLCursorDict cursor class returns
each row as a dictionary. The keys for each dictionary
object are the column names of the MySQL result.
cursor = cnx.cursor(dictionary=True)
MySQLCursorBufferedDict cursor class
MySQLCursorDict, but fetches the
entire result set after executing the query and buffers the
cursor = cnx.cursor(dictionary=True, buffered=True)
MySQLCursorNamedTuple cursor class
returns each row as a named tuple. Each column is accessible
through an attribute of the tuple-like object.
cursor = cnx.cursor(named_tuple=True)
class is like
fetches the entire result set after executing the query and
buffers the rows.
cursor = cnx.cursor(named_tuple=True, buffered=True)
For more information, see cursor.MySQLCursor Subclasses.
The packaging modules and supporting files have been removed from the main repository and from the source packages for Connector/Python. They are still available in the Connector/Python 1.x series.
TimeField values of
00:00:00 were incorrectly converted to
NULL because Python considered that value
(Bug #72732, Bug #18956789)
Fetching results from a prepared statement that returned many columns could produce an error. (Bug #72602, Bug #18742429)
RuntimeError exception was
raised when a Django application was inactive for a while. Now,
the Django backend verifies that the database connection is
still valid each time a database request is made.
(Bug #72545, Bug #18843153)