如果你伺服器環境允許yum,安裝MySQL-python子產品就很簡單了
[python] view plain copy
- yum install MySQL-python -y
當然也可以源碼安裝該子產品
首先安裝 setuptools,下載下傳源代碼包:
[plain] view plain copy
- 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
最後安裝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安裝位置定義)
測試安裝
- [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