一、下载,解压python-mysql
python
二、运行python setup.py installmysql
三、Error1: 报错mysql_config not foundsql
首先查找mysql_config的位置,使用find / -name mysql_configshell
其次、修改setup_posix.py文件apache
mysql_config.path = "mysql_config" 改成ide
mysql_config.path = "/usr/local/mysql/bin/mysql_config" # 这里的路径是本身系统的mysql_config的路径spa
四、Error2: .net
In file included from _mysql.c:29: pymemcompat.h:10:20: error: Python.h: No such file or directory _mysql.c:30:26: error: structmember.h: No such file or directory In file included from /usr/include/mysql/mysql.h:44, from _mysql.c:40: . . . _mysql.c:2808: warning: return type defaults to 'int' _mysql.c: In function 'DL_EXPORT': _mysql.c:2808: error: expected declaration specifiers before 'init_mysql' _mysql.c:2886: error: expected '{' at end of input error: command 'gcc' failed with exit status 1
须要安装python-develcode
yum install python-devel
五、Error3:在运行,import MySQLdb 时报ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directoryserver
将安装的mysql的lib中的libmysqlclient.so.18作个然链接就ok了,
>>> find / -name libmysqlclient.so.18 >>> ln -s /usr/local/server/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18 >>> ldconfig # 当即生效
六、Error4:在运行,import MySQLdb 时报ImportError: libssl.so.1.0.0: cannot open shared object file: No such file or directory
find / -name libssl.so.1.0.0 ln -s /opt/lamp/lib/libssl.so.1.0.0 /usr/lib ldconfig
///////////////////////// 分割线 //////////////////////////////
(2014-03-08更新,开源中国社区)
七、使用一种完美解决python-mysqldb安装的方式:(不要问,为何,反正运行了,就能够避免不少错误)
yum install gcc python-devel mysql-devel -y
上面运行事后,会解决一些MySQLdb使用到的一些依赖;
八、若是你是在Centos下安装的MySQLdb,安装完成后,在/usr/lib64/python2.6/site-packages/生成相应的egg文件,我使用的是1.2.5;可能在使用apache部署投入生产环境使用的时候,会有
kages/setuptools-2.2-py2.6.egg/pkg_resources.py:991: UserWarning: /root/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
那就须要在apache链接python模块时指定PYTHON_EGG_CACHE,我使用的是{{ 项目名称 }}/wsgi.py的方式作链接,在wsgi.py里添加:
os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs'
持续更新。。。
郑重声明,未经本人容许,不得任何形式的转载和copy,请尊重原版;http://my.oschina.net/shniu/admin/edit-blog?blog=205379