安装很简单,步骤如下:

前期:yum -y install python-setuptools,或者自己网上找源码包安装

1. 下载安装包:

#wget  https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip --no-check-certificate

#unzip  MySQL-python-1.2.5.zip

#cd MySQL-python-1.2.5

#python setup.py build

[root@ MySQL-python-1.2.5]# python setup.py  build
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.6
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.6
creating build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-2.6/MySQLdb
creating build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-2.6
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX -DUNIV_LINUX
In file included from /usr/include/mysql/my_config.h:14,
from _mysql.c:44:
/usr/include/mysql/my_config_x86_64.h:1082:1: warning: "HAVE_WCSCOLL" redefined
In file included from /usr/include/python2.6/pyconfig.h:6,
from /usr/include/python2.6/Python.h:8,
from _mysql.c:29:
/usr/include/python2.6/pyconfig-64.h:808:1: warning: this is the location of the previous definition
gcc -pthread -shared build/temp.linux-x86_64-2.6/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lpython2.6 -o build/lib.linux-x86_64-2.6/_mysql.so

#python setup.py install

[root@MySQL-python-1.2.5]# python setup.py install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdb
running build_ext
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.6/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdb
creating build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.6/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.6/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.6/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.6/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.6/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.6/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.6/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.6/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.6/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.6/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.6/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.6/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.6/_mysql.so -> build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.6/_mysql_exceptions.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pyc
byte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
creating stub loader for _mysql.so
byte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/MySQL_python-1.2.5-py2.6-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing MySQL_python-1.2.5-py2.6-linux-x86_64.egg
creating /usr/lib64/python2.6/site-packages/MySQL_python-1.2.5-py2.6-linux-x86_64.egg
Extracting MySQL_python-1.2.5-py2.6-linux-x86_64.egg to /usr/lib64/python2.6/site-packages
Adding MySQL-python 1.2.5 to easy-install.pth file Installed /usr/lib64/python2.6/site-packages/MySQL_python-1.2.5-py2.6-linux-x86_64.egg
Processing dependencies for MySQL-python==1.2.5
Finished processing dependencies for MySQL-python==1.2.5

测试:

[root@ MySQL-python-1.2.5]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> quit() 未成功安装测试时会提示:
>>> import mysqldb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysqldb

安装时遇到的错误:

若在执行python setup.py build时报错报EnvironmentError: mysql_config not found,需要进行如下操作:

1. 使用find / -name mysql_config查找mysql_config的位置,如/usr/bin/mysql/mysql_config

2. 修改MySQL-python-1.2.5 /site.cfg文件,去掉mysql_config=XXX注释,并改成mysql_config=/usr/bin/mysql/mysql_config

3. 如果没有mysql_config命令,则需要安装如下包:

yum -y install mysql-server mysql-devel mysql-shared

MySQLdb-python安装的更多相关文章

  1. Python的MySQLdb模块安装,连接,操作,增删改

    1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本     python -V   检查python版本 2. 安装mysql, 比如安装在/usr/local/my ...

  2. Python MySQLdb Mac安装遇到的问题

    Mac 下使用Python 连接Mysql 数据库,使用到模块MySQLdb,各种问题都出现,搜集整理下,最后发现最关键的还是Mac 下的Python 版本问题 前置条件: 1. 已经安装mysql ...

  3. python之mysqldb模块安装

    之所以会写下这篇日志,是因为安装的过程有点虐心.目前这篇文章是针对windows操作系统上的mysqldb的安装.安装python的mysqldb模块,首先当然是找一些官方的网站去下载:https:/ ...

  4. Python 安装requests和MySQLdb

    Python 安装requests和MySQLdb 2017年10月02日 0.系统版本 0.1 查看系统版本 [root@localhost ~]# uname -a Linux localhost ...

  5. windows(32位 64位)下python安装mysqldb模块

    windows(32位 64位)下python安装mysqldb模块 www.111cn.net 编辑:mengchu9 来源:转载 本文章来给各位使用在此windows系统中的python来安装一个 ...

  6. python 安装cx_Oracle模块, MySQLdb模块, Tornado

    一,想访问远程Oracle数据库,本地又不想安装几百兆的Oracle Client(也木有root权限),安装python的cx_Oralce 模块需要依赖Oracle Instant Client ...

  7. centos6.3环境下升级python及MySQLdb的安装

    近来突然想鼓捣下linux下的python,看下Python数据库方面的东西,想着在centos下测试下.然而安装的过程有很多坑.下面对整个流程进行下记录 1.python基本库的安装 在安装pyth ...

  8. Pthon MySQLdb 的安装

    说明: 要用python 去连接MySQL我们需要一个驱动程序这个程序就是MySQL-python,所以我们首先就是要下一个对应版本的MySQL-python (注意这个驱动程序只有32位版本的,所以 ...

  9. Mac MySQLdb模块安装,可算解决了

    转载:http://blog.csdn.net/janronehoo/article/details/25207825 短评:这篇文章感觉是比较全面解决Mac MySQLdb模块安装问题的文章了,特别 ...

  10. python安装pyMysql

    python2和python3是不兼容的,在python2中,链接数据库使用的是mysqldb,但在python3中是是pyMysql. 1.首先dos进入python安装目录,找到并进入Script ...

随机推荐

  1. CSS基础知识总结二

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> ...

  2. iOS---如何截图,如何将图片保存到相册

    最近的项目中运用到了这两个功能,所以记录一下.做了一个小工程将两个方法结合到了一起 1 - (void)viewDidLoad { [super viewDidLoad]; UIButton * bt ...

  3. Ckeditor IE下粘贴word中图片问题

    自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...

  4. Codeforces Round #608 (Div. 2) E - Common Number (二分 思维 树结构)

  5. 【2019 Multi-University Training Contest 9】

    01: 02:https://www.cnblogs.com/myx12345/p/11666961.html 03: 04: 05:https://www.cnblogs.com/myx12345/ ...

  6. DELPHI 把数据库中的数据转换成XML格式

    function ReplaceString(AString: string): string; begin Result := StringReplace(AString, '&', '&a ...

  7. ztree 拖动树结构的移动组件样式不见了怎么办?

    这个是没有设置z-index被其他层级高的掩盖了. 修改方法: zTreeStyle.css中设置 结果:

  8. (转)【mysql元数据库】使用information_schema.tables查询数据库和数据表信息 ---数据记录大小统计

    转:https://www.cnblogs.com/ssslinppp/p/6178636.html https://segmentfault.com/q/1010000007268994?_ea=1 ...

  9. jmeter 命令行运行与生成报告

    一.     使用命令行方式运行Jmeter 1.1 为什么 使用GUI方式启动jmeter,运行线程较多的测试时,会造成内存和CPU的大量消耗,导致客户机卡死. 所以正确的打开方式是在GUI模式下调 ...

  10. 三层for循环求解组成三角形边的组合

    假设a.b.c是三角形的三条边,当三条边符合勾股定理时,即,a2+b2=c2 ,为直角三角形.若a.b.c均为小于等于50的整数,求能够组成直角三角形的所有组合.请显示边的各种可能组合情况,显示总的组 ...