MySQL Connectivity With Python - Getting Started
(Page 2 of 7 )
In the words of its author, MySQLdb is "a thread-compatible interface to the popular MySQL database server that provides the Python database API." Developed by Andy Dustman, this module is needed for MySQL database connectivity under Python.
The first thing to do is make sure that you have the MySQLdb module installed on your Python development system. The easiest way to check this via the interactive Python command line interpreter - as the following example demonstrates:
Python 1.5.2 (#1, Feb 1 2000, 16:32:16) [GCC egcs-2.91.66
19990314/Linux
(egcs- on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import MySQLdb
Traceback (innermost last):
File "<stdin>", line 1, in ?
ImportError: No module named MySQLdb
>>>
If you see something like the error message above, you can safely assume that the module is not installed on your system. Drop by
http://sourceforge.net/projects/mysql-python, download the latest copy of the MySQLdb distribution, and extract and install it on your system.
$ tar -xzvf MySQL-python-0.9.2.tar.gz
$ cd MySQL-python-0.9.2
$ python setup.py build
$ python setup.py install
Now, you can verify that the module has been installed by trying to import it again via the command line.
Python 1.5.2 (#1, Feb 1 2000, 16:32:16) [GCC egcs-2.91.66
19990314/Linux
(egcs- on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import MySQLdb
>>>
No problems this time round - which means we can proceed to actually writing some code.
Next: Animal Antics >>
More Python Articles
More By icarus, (c) Melonfire