如果你服务器环境允许yum,安装MySQL-python模块就很简单了。
如果直接安装不行,先
安装MySQL-devel后正常运行
yum install mysql-devel
yum install MySQL-python -y
1 | yum install MySQL–python –y |
当然也可以源码安装该模块
首先安装 setuptools,下载源代码包:
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz 解压后 python setup.py build python setup.py install
1 2 3 4 5 | wget http://pypi.python.org/packages/source/s/setuptools/setuptools–0.6c11.tar.gz 解压后 python setup.py build python setup.py install |
然后安装一些扩展库
yum -y install rpm-build gcc-c++ mysql-devel python-devel
1 | yum –y install rpm–build gcc–c++ mysql–devel python–devel |
最后安装MySQL-python
下载源代码包: wget http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz 解压进入安装目录。 编辑 site.cfg ,把 mysql_config 那一行取消注释,并改为: mysql_config = /usr/lib64/mysql/mysql_config (根据自己mysql安装位置定义) python setup.py build python setup.py install
1 2 3 4 5 6 7 8 | 下载源代码包: wget http://download.sourceforge.net/sourceforge/mysql–python/MySQL–python–1.2.3.tar.gz 解压进入安装目录。 编辑 site.cfg ,把 mysql_config 那一行取消注释,并改为: mysql_config = /usr/lib64/mysql/mysql_config (根据自己mysql安装位置定义) python setup.py build python setup.py install |
测试安装
[root@woyoo:/tmp/MySQL-python-1.2.3]# python Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> import MySQLdb /usr/lib64/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.pyc, but /tmp/MySQL-python-1.2.3 is being added to sys.path >>>
1 2 3 4 5 6 7 | [root@woyoo:/tmp/MySQL–python–1.2.3]# python Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18) [GCC 4.4.7 20120313 (Red Hat 4.4.7–3)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> import MySQLdb /usr/lib64/python2.6/site–packages/MySQL_python–1.2.3–py2.6–linux–x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.6/site–packages/MySQL_python–1.2.3–py2.6–linux–x86_64.egg/_mysql.pyc, but /tmp/MySQL–python–1.2.3 is being added to sys.path >>> |
报出一大堆警告信息,解决办法:删除MySQL-python源目录,再测试一下: