Documentation Home
MySQL Connector/Python Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.6Mb
PDF (A4) - 0.6Mb
HTML Download (TGZ) - 83.0Kb
HTML Download (Zip) - 95.7Kb


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 a MySQLConnection 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 its execute() method raises an exception.


User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.