1、下载mysql-python
官网地址:http://sourceforge.net/projects/mysql-python/
2、安装mysql-python
# tar -zxvf MySQL-python-1.2.3.tar.gz
# cd MySQL-python-1.2.3
# whereis mysql_config
mysql_config: /usr/bin/mysql_config /usr/share/man/man1/mysql_config.1.gz
# vi site.cfg
threadsafe = False
mysql_config = /usr/bin/mysql_config
# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
# export LD_LIBRARY_PATH=/usr/include/mysql
# python setup.py build
# python setup.py install
注意:
1.编译mysql-python需要mysql头文件。
2.安装mysql-python需要setuptools工具。
3、测试
# python
>>> import MySQLdb
>>>
如果没有错误提示或者以下错误提示,那么表示安装成功。
错误提示:
/usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.pyc, but /root/MySQL-python-1.2.3 is being added to sys.path
报错原因:
执行python setup.py install,MySQLdb模块会被拷贝python的site-packages目录。如果在执行python的目录中存在相同的模块,就可能重复导入模块。
解决办法:
换个目录执行python即可。