MySQL Connector/Python Developer Guide / ... / Connector/Python API Reference / cursor.MySQLCursor Class / cursor.MySQLCursor Constructor
In most cases, theMySQLConnectioncursor() method is used to instantiate aMySQLCursor object:
import mysql.connectorcnx = mysql.connector.connect(database='world')cursor = cnx.cursor() It is also possible to instantiate a cursor by passing aMySQLConnection object toMySQLCursor:
import mysql.connectorfrom mysql.connector.cursor import MySQLCursorcnx = mysql.connector.connect(database='world')cursor = MySQLCursor(cnx) The connection argument is optional. If omitted, the cursor is created but itsexecute() method raises an exception.