- 10.5.1 cursor.MySQLCursor Constructor
- 10.5.2 MySQLCursor.add_attribute() Method
- 10.5.3 MySQLCursor.clear_attributes() Method
- 10.5.4 MySQLCursor.get_attributes() Method
- 10.5.5 MySQLCursor.callproc() Method
- 10.5.6 MySQLCursor.close() Method
- 10.5.7 MySQLCursor.execute() Method
- 10.5.8 MySQLCursor.executemany() Method
- 10.5.9 MySQLCursor.fetchall() Method
- 10.5.10 MySQLCursor.fetchmany() Method
- 10.5.11 MySQLCursor.fetchone() Method
- 10.5.12 MySQLCursor.fetchwarnings() Method
- 10.5.13 MySQLCursor.stored_results() Method
- 10.5.14 MySQLCursor.column_names Property
- 10.5.15 MySQLCursor.description Property
- 10.5.16 MySQLCursor.lastrowid Property
- 10.5.17 MySQLCursor.rowcount Property
- 10.5.18 MySQLCursor.statement Property
- 10.5.19 MySQLCursor.with_rows Property
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)
-
MySQLCursorBufferedRaw
creates a buffered raw cursor. See Section 10.6.3, “cursor.MySQLCursorBufferedRaw Class”.cursor = cnx.cursor(raw=True, buffered=True)
-
MySQLCursorDict
creates a cursor that returns rows as dictionaries. See Section 10.6.4, “cursor.MySQLCursorDict Class”.cursor = cnx.cursor(dictionary=True)
-
MySQLCursorBufferedDict
creates a buffered cursor that returns rows as dictionaries. See Section 10.6.5, “cursor.MySQLCursorBufferedDict Class”.cursor = cnx.cursor(dictionary=True, buffered=True)
-
MySQLCursorNamedTuple
creates a cursor that returns rows as named tuples. See Section 10.6.6, “cursor.MySQLCursorNamedTuple Class”.cursor = cnx.cursor(named_tuple=True)
-
MySQLCursorBufferedNamedTuple
creates a buffered cursor that returns rows as named tuples. See Section 10.6.7, “cursor.MySQLCursorBufferedNamedTuple Class”.cursor = cnx.cursor(named_tuple=True, buffered=True)
-
MySQLCursorPrepared
creates a cursor for executing prepared statements. See Section 10.6.8, “cursor.MySQLCursorPrepared Class”.cursor = cnx.cursor(prepared=True)