若是你服務器環境容許yum,安裝MySQL-python模塊就很簡單了。python
若是直接安裝不行,先mysql
安裝MySQL-devel後正常運行linux
yum install mysql-develc++
1
|
yum install MySQL-python -y
|
固然也能夠源碼安裝該模塊web
首先安裝 setuptools,下載源代碼包:sql
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
|
而後安裝一些擴展庫sublime-text
1
|
yum -y install rpm-build gcc-c++ mysql-devel python-devel
|
最後安裝MySQL-python服務器
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
|
測試安裝測試
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源目錄,再測試一下:ui