8.2 The _mysql_connector C Extension Module (original) (raw)

To use the C Extension directly, import the_mysql_connector module rather thanmysql.connector, then use the_mysql_connector.MySQL() class to obtain aMySQL instance. For example:

import _mysql_connector

ccnx = _mysql_connector.MySQL()
ccnx.connect(user='scott', password='password',
             host='127.0.0.1', database='employees')

ccnx.query("SHOW VARIABLES LIKE 'version%'")
row = ccnx.fetch_row()
while row:
  print(row)
  row = ccnx.fetch_row()
ccnx.free_result()

ccnx.close()

For more information, seeChapter 11, Connector/Python C Extension API Reference.