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
bytearraytype. 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 is:
To get the same value as in Connector/Python 1.x, do this:
Using Python 2:
Using Python 3:
Important Change: Previously, to enable use of
LOAD DATA LOCAL, clients had to explicitly set the
ClientFlag.LOCAL_FILESflag. This flag is now enabled by default. To disable it, the
connect()can be set to
For a stored procedure that produces multiple result sets, it is now possible to execute the procedure and process its results by executing a
CALLstatement. Execute the statement using
multi=Trueargument, 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 for
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 specified.
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.cursormodule supports four new cursor classes:
MySQLCursorDictcursor 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)
MySQLCursorBufferedDictcursor class is like
MySQLCursorDict, but fetches the entire result set after executing the query and buffers the rows.
cursor = cnx.cursor(dictionary=True, buffered=True)
MySQLCursorNamedTuplecursor 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)
MySQLCursorBufferedNamedTuplecursor class is like
MySQLCursorNamedTuple, but 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 Subclasses cursor.MySQLCursor.
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.
00:00:00were incorrectly converted to
NULLbecause Python considered that value equal to
False. (Bug #72732, Bug #18956789)
Fetching results from a prepared statement that returned many columns could produce an error. (Bug #72602, Bug #18742429)
RuntimeErrorexception was raised when a Django application was inactive for a while. Now, the Django back end verifies that the database connection is still valid each time a database request is made. (Bug #72545, Bug #18843153)