下载:wget http://sourceforge.net/projects/mysql-python/files/latest/downloa
cd /root/MySQL-python-1.2.4b4
tar -zxvf MySQL-python-1.2.4b4.tar.gz
# vi site.cfg
embedded = False
threadsafe = True
static = False
mysql_config = /usr/local/mysql/bin/mysql_config
# python setup.py build
#python setup.py install
#python
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
>>>
原因是python无法找到mysql目录下的libmysqlclient_r.so.16动态库,其实MySQLdb是调用mysql的c函数库.本机上首先得安装了mysql
# ln -s /usr/local/mysql/lib/mysql/libmysqlclient_r.so.16 /usr/lib