Centos6.7下安装python连接mysql环境故障解决

在Python连接和使用MysqL时,需要调用MysqLdb 模块,是用于Python链接MysqL数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MysqL C API 上建立的。

MysqLdb模块在不同的平台下安装方式不一样,这里主要介绍Linux下的安装方式,https://pypi.python.org/pypi/MySQL-python 可以在这里选择合适的版本,解压安装。

安装步骤:

1、选择合适的版本以及检查相关路径
这里选择版本为MysqL-python-1.2.5.zip,下面是下载路径与过程。
wgethttps://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MysqL-python-1.2.5.zip
--2016-10-0821:34:56--https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MysqL-python-1.2.5.zip
Resolvingpypi.python.org...151.101.76.223,2a04:4e42:12::223
Connectingtopypi.python.org|151.101.76.223|:443...connected.
HTTPrequestsent,awaitingresponse...200OK
Length:108935(106K)[application/octet-stream]
Savingto:“MysqL-python-1.2.5.zip”

100%[======================================================>]108,935--.-K/sin0.1s

2016-10-0821:34:57(1.00MB/s)-“MysqL-python-1.2.5.zip”saved[108935/108935]

[root@localhostpython]#ls
MysqL.pyMysqL-python-1.2.5.zip
解压:
[root@localhostpython]#unzipMysqL-python-1.2.5.zip
Archive:MysqL-python-1.2.5.zip
inflating:MysqL-python-1.2.5/GPL-2.0
inflating:MysqL-python-1.2.5/HISTORY
inflating:MysqL-python-1.2.5/INSTALL
inflating:MysqL-python-1.2.5/MANIFEST.in
inflating:MysqL-python-1.2.5/Metadata.cfg
inflating:MysqL-python-1.2.5/PKG-INFO
inflating:MysqL-python-1.2.5/pymemcompat.h
inflating:MysqL-python-1.2.5/README.md
inflating:MysqL-python-1.2.5/setup.cfg
inflating:MysqL-python-1.2.5/setup.py
inflating:MysqL-python-1.2.5/setup_common.py
inflating:MysqL-python-1.2.5/
切换到解压目录安装:
使用命令pythonsetup.pybuild&&pythonsetup.pyinstall

安装报错:

[root@localhostMysqL-python-1.2.5]#pythonsetup.pybuild
Traceback(mostrecentcalllast):
File"setup.py",line7,in<module>
importsetuptools
ImportError:Nomodulenamedsetuptools
提示缺少setuptools可以在


安装命令和上面一样,等最后执行完毕没有报错,安装成功,我们继续安装上面的。
pythonsetup.pybuild
runningbuild
runningbuild_py
creatingbuild
creatingbuild/lib
copyingpkg_resources.py->build/lib
copyingeasy_install.py->build/lib
copyingsite.py->build/lib
creatingbuild/lib/setuptools
copyingsetuptools/package_index.py->build/lib/setuptools
copyingsetuptools/depends.py->build/lib/setuptools
copyingsetuptools/extension.py->build/lib/setuptools
copyingsetuptools/__init__.py->build/lib/set
。。。。。。

Installed/usr/local/python2.7.11/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processingdependenciesforsetuptools==0.6c11
Finishedprocessingdependenciesforsetuptools==0.6c11
[root@localhostsetuptools-0.6c11]#cd..

继续安装MysqL-python出现error:command'gcc'Failedwithexitstatus1可以用以下命令解决

yuminstallgccpython-develMysqL-devellibxml2libxml2-devlibxslt*zlibgccopenssl

安装完成后的检验:

在shell窗口调用Python命令,然后执行,不报错即可

importMysqLdb

相关文章

有时候CentOS工作在无互联网的环境下,需要在离线环境下安装一些组件,这次实现的是模拟在离线环境下安...
首先参照https://www.cnblogs.com/wdw984/p/13330074.html,来进行如何安装Centos和离线下载rpm包。 离...
有两个.NET CORE3.1网站部署在CentOS7上(内网IP是192.168.2.32),现在想实现访问http://192.168.2.32...
1、yum -y install vsftpd 安装vsftpd 2、配置vsftpd的配置文件(/etc/vsftpd/vsftpd.conf)主要修改以...
首先去mysql官网下载mysql的离线rpm安装包(https://downloads.mysql.com/archives/community/) Mysql...
第一步下载erlang环境并安装: wget https://packages.erlang-solutions.com/erlang/rpm/centos/7/x86_...