MySQL II : Python

Setting Up MySQL With Python

1. Go to http://www.sourcekeg.co.uk/www.python.org/2.4.2/rpms.html and get python24-2.4.2-2.i386.rpm.

Install this by issuing the command:

rpm -i python24-2.4.2-2.i386.rpm

(Historical note: you can get a tarball and install it like this:

Go to http://python.org/2.4.2/ and get Python 2.4.2 (http://python.org/ftp/python/2.4.2/Python-2.4.2.tgz or http://python.org/ftp/python/2.4.2/Python-2.4.2.tar.bz2 – the bz2 is smaller). Copy or move it to /usr/local/ and unpack with:

tar -zxvf Python-2.4.2.tgz
or
bzcat Python-2.4.2.tar.bz2 | tar -x
f –

Then:

./configure
make
make install

)

2. Go to http://rpm.pbone.net/index.php3/stat/4/idpl/1953238/com/python-devel-2.4.1-2.i386.rpm.html to get python-devel-2.4.1-2.i386.rpm. Install this:

rpm -i python-devel-2.4.1-2.i386.rpm

 

This is the Python interface to MySQL.

1.  Go to http://sourceforge.net/projects/mysql-python/ and download (http://prdownloads.sourceforge.net/mysql-python/MySQL-python-1.2.0.tar.gz?download).

2. Get the README (http://sourceforge.net/docman/display_doc.php?docid=26237&group_id=22307) and review it.

3. Generally your installation will be like this:

tar xfz MySQL-python-1.1.8.tar.gz
cd MySQL-python-1.1.8
export mysqlversion=”5.0.16″
export mysqlclient=”mysqlclient_r”
export mysqloptlibs=”ssl crypto”
python setup.py build
su # or use sudo
python setup.py install

 

If you’re going to follow the demonstration on the Python Development page, you’ll need the following packages as well.

 

fpconst is a development library necessary for the SOAPy component. Go to http://research.warnes.net/downloads/ and get the latest .gz version of fpconst.

Extract the tarball and go into the resulting directory from the command line. Command:

python setup.py install

You’re done here.

 

pyXML is another package of libraries for processing XML using Python. Go to http://pyxml.sourceforge.net and download the latest .tar.gz file.

Extract the tarball and go into the resulting directory from the command line. Command:

python setup.py build

(Yes, there’s an extra step to compile this package.) Now command:

python setup.py install

Finito. (This isn’t that hard, is it?)

 

Go to http://sourceforge.net/project/showfiles.php?group_id=26590 and get SOAPy (download SOAP.py-<version>.tar.gz).

Extract the tarball and go into the resulting directory from the command line. Command:

python setup.py install

That’s it. You’ve gotta love python.

 

See “Writing MySQL Scripts with Python DB-API” by Paul DuBois at http://www.kitebird.com/articles/pydbapi.html. Run this test:

python
>>> import sys
>>> sys.version
#You should get results similar to:
‘1.5.2 (#1, Aug 25 2000, 09:33:37) [GCC 2.96 20000731 (experimental)]’
>>> import MySQLdb

This should return you to the prompt:

>>>

If instead you get:

>>> import MySQLdb
Traceback (most recent call last):
File “<stdin>”, line 1, in ?
ImportError: No module named MySQLdb

then it’s time to go to the top of the list and review what you’ve done.