如何在centos安装python-mysql
1个回答
2016-12-09
展开全部
如果你服务器环境允许yum,安装MySQL-python模块就很简单了
yum install MySQL-python -y
当然也可以源码安装该模块
首先安装 setuptools,下载源代码包:
解压后
python setup.py build
python setup.py install
然后安装一些扩展库
yum -y install rpm-build gcc-c++ mysql-devel python-devel
最后安装MySQL-python
下载源代码包:
解压进入安装目录。
编辑 site.cfg ,把 mysql_config 那一行取消注释,并改为:
mysql_config = /usr/lib64/mysql/mysql_config (根据自己mysql安装位置定义)
python setup.py build
python setup.py install
测试安装
Shell
[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源目录,再测试一下:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |