MySQL Connector/Python 发行说明
大多数情况下,使用 MySQLConnection 的 cursor() 方法实例化 MySQLCursor 对象。
import mysql.connector
cnx = mysql.connector.connect(database='world')
cursor = cnx.cursor()
也可以通过将 MySQLConnection 对象传递给 MySQLCursor 来实例化游标。
import mysql.connector
from mysql.connector.cursor import MySQLCursor
cnx = mysql.connector.connect(database='world')
cursor = MySQLCursor(cnx)
连接参数是可选的。如果省略,则会创建游标,但其 execute() 方法会引发异常。