Main Content

Python to MySQL

Archive - Originally posted on "The Horse's Mouth" - 2006-03-31 06:46:22 - Graham Ellis

We've added some Python to MySQL connection examples on our web site - using the mysql-python open source download from sourceforge.

For the installation, you MUST ensure that you have the MySQL include files and libraries installed before you attempt a build, and that you set your PATH to point to that version of MySQL - otherwise you can get a rather frightening page full of errors. Here's a checklist for you:

1. Install MySQL into /usr/local

2. set up mysql-python
download, unzip and untar, cd to directory.
export mysqlclient=mysqlclient
export PATH=/usr/local/mysql/bin:$PATH
python setup.py build


3. Install mysql-python
become administrator
python setup.py install

I've run the above on both Fedora and Suse ...

Sample program sources:
Hello PySQL world, documented
Bare bones application using recommended classes
Example of using a MySQL database from Python in a web based (CGI) application