Importing MySQL for Python

The name of the project MySQL for Python is the current version of a project that began under the rubric MySQLdb. Consequently, unlike most Python modules, the MySQL for Python module is not called by its name, but by its historic handle. To import the module, insert the following into a Python program or simply type it in a following Python shell:

import MySQLdb

To make working with the module easier, you can also import it with an alias:

import MySQLdb as mysql

This allows us to use mysql instead of MySQLdb when we access parts of the module.

When you do this, several things will occur. You need not be concerned about most of them, but you should be aware that MySQLdb depends upon a module called _mysql. The _mysql module ...

Get MySQL for Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.