1. 下载 MySQL-python-1.2.3.tar.gz
    地址 https://sourceforge.net/projects/mysql-python/

2. 安装 MySQl-python
    tar xvf MySQL-python-1.2.3.tar.gz
    cd MySQL-python-1.2.3
    vi site.cfg
    把 mysql_config = /usr/local/mysql/bin/mysql_config 这一行前的#去掉,并且把mysql_config的路径设置正确。
    python setup.py build
    运行上面的命令报错如下:

 [root@localhost MySQL-python-1.2.3]# python setup.py  install
Traceback (most recent call last):
  File "setup.py", line 5, in ?
    from setuptools import setup, Extension
ImportError: No module named setuptools

解决方法:

wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install

继续安装:

python setup.py build
python setup.py install

运行测试:

 [root@localhost MySQL-python-1.2.3]# python
Python 2.4.3 (#1, Sep  3 2009, 15:37:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/usr/lib64/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-x86_64.egg/_mysql.pyc, but /opt/python/MySQL-python-1.2.3 is being added to sys.path
>>>

报出一大堆警告信息,解决办法:删除MySQL-python源目录,再测试一下:

 [root@localhost python]# python
Python 2.4.3 (#1, Sep  3 2009, 15:37:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

Mysql模块终于正常了!