MySQL :: MySQL Connector/Python Developer Guide :: 10.5.1 cursor.MySQLCursor Constructor (original) (raw)
The world's most popular open source database
10.5.1 cursor.MySQLCursor Constructor
In most cases, the MySQLConnection
cursor() method is used to instantiate a MySQLCursor
object:
import mysql.connector
cnx = mysql.connector.connect(database='world')
cursor = cnx.cursor()
It is also possible to instantiate a cursor by passing aMySQLConnection object to MySQLCursor
:
import mysql.connector
from mysql.connector.cursor import MySQLCursor
cnx = 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.