MySQL Connector/Python Developer Guide
The MySQLCursor
class instantiates objects that
can execute operations such as SQL statements. Cursor objects
interact with the MySQL server using a
MySQLConnection
object.
To create a cursor, use the
cursor()
method of a connection object:
import mysql.connector cnx = mysql.connector.connect(database='world') cursor = cnx.cursor()
Several related classes inherit from
MySQLCursor
. To create a cursor of one of these
types, pass the appropriate arguments to
cursor()
:
MySQLCursorBuffered
creates a buffered
cursor. See
Section 10.6.1, “cursor.MySQLCursorBuffered Class”.
cursor = cnx.cursor(buffered=True)
MySQLCursorRaw
creates a raw cursor. See
Section 10.6.2, “cursor.MySQLCursorRaw Class”.
cursor = cnx.cursor(raw=True)
MySQLCursorDict
creates a cursor that
returns rows as dictionaries. See
Section 10.6.3, “cursor.MySQLCursorDict Class”.
cursor = cnx.cursor(dictionary=True)
MySQLCursorBufferedDict
creates a buffered
cursor that returns rows as dictionaries. See
Section 10.6.4, “cursor.MySQLCursorBufferedDict Class”.
cursor = cnx.cursor(dictionary=True, buffered=True)
MySQLCursorPrepared
creates a cursor for
executing prepared statements. See
Section 10.6.5, “cursor.MySQLCursorPrepared Class”.
cursor = cnx.cursor(prepared=True)