首页 > 代码库 > Centos6.7下安装python连接mysql环境故障解决
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,下面是下载路径与过程。 wget https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip --2016-10-08 21:34:56-- https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip Resolving pypi.python.org... 151.101.76.223, 2a04:4e42:12::223 Connecting to pypi.python.org|151.101.76.223|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 108935 (106K) [application/octet-stream] Saving to: “MySQL-python-1.2.5.zip” 100%[======================================================>] 108,935 --.-K/s in 0.1s 2016-10-08 21:34:57 (1.00 MB/s) - “MySQL-python-1.2.5.zip” saved [108935/108935] [root@localhost python]# ls mysql.py MySQL-python-1.2.5.zip 解压: [root@localhost python]# unzip MySQL-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/ 切换到解压目录安装: 使用命令 python setup.py build && python setup.py install 安装报错: [root@localhost MySQL-python-1.2.5]# python setup.py build Traceback (most recent call last): File "setup.py", line 7, in <module> import setuptools ImportError: No module named setuptools 提示缺少setuptools 可以在 安装命令和上面一样,等最后执行完毕没有报错,安装成功,我们继续安装上面的。 python setup.py build running build running build_py creating build creating build/lib copying pkg_resources.py -> build/lib copying easy_install.py -> build/lib copying site.py -> build/lib creating build/lib/setuptools copying setuptools/package_index.py -> build/lib/setuptools copying setuptools/depends.py -> build/lib/setuptools copying setuptools/extension.py -> build/lib/setuptools copying setuptools/__init__.py -> build/lib/set 。。。。。。 Installed /usr/local/python2.7.11/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg Processing dependencies for setuptools==0.6c11 Finished processing dependencies for setuptools==0.6c11 [root@localhost setuptools-0.6c11]# cd .. 继续安装MySQL-python 出现error: command ‘gcc‘ failed with exit status 1可以用以下命令解决 yum install gcc python-devel mysql-devel libxml2 libxml2-dev libxslt* zlib gcc openssl
安装完成后的检验:
在shell窗口调用Python命令,然后执行,不报错即可
import MySQLdb
Centos6.7下安装python连接mysql环境故障解决
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。