As a novice in the world of Python, I was searching for a way to connect to mysql db using python. And found the cool example from devshed that shows connectivity using MySqLdb module. Default installation of Python may not contain MySQLdb Module, in that case you have to install it manually.
First check whether its already installed ot not:
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 “”, line 1, in ?
ImportError: No module named MySQLdb
>>>
ImportError: No module named MySQLdb >> indicate that you dont have MySQLdb installed.
According to devshed it just 4 line matter to install MySQLdb as follows:
$ tar -xzvf MySQL-python-0.9.2.tar.gz
$ cd MySQL-python-0.9.2
$ python setup.py build
$ python setup.py install
I was trying to build it in My dedicated server running on CentOS.
Every time I am trying to run
>> python setup.py build
it end up with following error.
error: command ‘gcc’ failed with exit status 1
After some googling, some forum suggest to check whether gcc is installed or not,
Thats the problem, everyone was worried about only GCC, I installed it again and recheck, still the same
problem.
After spending some ‘faltoo’ time I found that the following things sould be installed within your system
to run MySQLdb properly
>> yum install python-devel
>> yum install MySQL-devel
>> yum install zlib-devel
>> yum install openssl-devel
Now its working fine
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
>>>
(Gives no error)