mysql-python的安装

安装过程遇到很多问题,备忘:

1、下载mysql-python

官网地址:http://sourceforge.net/projects/mysql-python/

#cd/usr/local

#wgethttp://nchc.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz

2、解压

#tar-zxvfMySQL-python-1.2.2.tar.gz

#cdMySQL-python-1.2.2

3、在安装前要做下面几步

a、修改setup_posix.py中的mysql_config.path为你mysql安装目录的mysql_config路径

b、修改site.cfg中的threadsafe=False,mysql_config=/usr/local/mysql/bin/mysql_config

c、执行命令:(注意这个地方,三条命令都执行)

#exportLD_LIBRARY_PATH=/usr/local/mysql/lib/mysql

#ln-s/usr/local/mysql/lib/mysql/libmysqlclient.so/usr/lib/libmysqlclient.so.14

#ldconfig(这个重要)

否则后面会报错ImportError:libmysqlclient.so.14:cannotopensharedobjectfile

4、build和install

#pythonsetup.pybuild

#pythonsetup.pyinstall

5、使用

#python

#>>>importMySSQLdb

如果报错

/usr/lib/python2.3/site-packages/MySQL_python-1.2.2-py2.3-linux-i686.egg/_mysql.py:3:UserWarning:Module_mysqlwasalreadyimportedfrom/usr/lib/python2.3/site-packages/MySQL_python-1.2.2-py2.3-linux-i686.egg/_mysql.pyc,but/usr/local/src/MySQL-python-1.2.2isbeingaddedtosys.path

原因是,install后MySQLdb模块已经被放到python的site-pachages目录中;但我在当前目录也存在相同的模块,所以可能会重复导入。只要切换到其他目录运行python就可以了。

相关推荐