$ tar xfz MySQL-python-1.2.1.tar.gz
$ cd MySQL-python-1.2.1
$ # edit site.cfg if necessary
$ python setup.py build
$ sudo python setup.py install # or su first
#上面這是文檔上給的安裝步驟
[root@zhu2 MySQL-python-1.2.3]# python setup.py build
Traceback (most recent call last):
File "setup.py", line 5, in ?
from setuptools import setup, Extension
ImportError: No module named setuptools
#這是由於python裡缺少setuptools這個模塊引起的。
#解決方法如下
https://pypi.python.org/pypi/setuptools#downloads
下載setuptools軟件安裝
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.3.tar.gz#md5=87680a0eb0bb6f720d5e2d89ba67debc --no-check-certificate
1.python連接mysql需要的模塊MySQLdb默認是沒有安裝的,所以需要單獨的安裝後才能使用,安裝的方法有編譯安裝和yum安裝。雖是個小模塊,但安裝時也遇到了一些問題。
編譯安裝:
1.下載所需軟件
http://sourceforge.net/projects/mysql-python/files/mysql-python/ #可在此地址下找到需要的版本。
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
#解壓
tar xf MySQL-python-1.2.3.tar.gz
2.安裝
[root@jiang MySQL-python-1.2.3]# python setup.py build
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup, Extension
ImportError: No module named setuptools
#這個報錯是由於缺少setuptools這個模塊引起的,解決方法如下:
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.3.tar.gz#md5=87680a0eb0bb6f720d5e2d89ba67debc
tar xf setuptools-3.3.tar.gz
python setup.py build
python setup.py install
繼續安裝
unable to execute gcc: No such file or directory
error: command 'gcc' failed with exit status 1
#出現這個錯誤時,解決方法如下:
yum -y install python-devel mysql-devel gcc
解決該錯誤後繼續安裝
[root@jiang MySQL-python-1.2.3]# python setup.py build
[root@jiang MySQL-python-1.2.3]# python setup.py install
這樣便可成功安裝
Processing MySQL_python-1.2.3-py2.6-linux-i686.egg
Copying MySQL_python-1.2.3-py2.6-linux-i686.egg to /usr/lib/python2.6/site-packages
Adding MySQL-python 1.2.3 to easy-install.pth file
Installed /usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg
Processing dependencies for MySQL-python==1.2.3
Finished processing dependencies for MySQL-python==1.2.3
檢測該模塊是否可成功使用
[root@jiang ~]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
假如mysql使用的是編譯安裝,那麼也可能碰到問題
mysql_config not found #找不到mysql的安裝路徑
vim setup_posix.py #找到第26行左右
mysql_config.path = "mysql_config" #修改為對應的mysql安裝路徑即可,比如
/opt/mysql/bin/mysql_config
#######################
/usr/bin/ld: cannot find -lmysqlclient_r #這個錯誤是找不到mysql的庫文件
解決方法:
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
ldconfig
如果沒有libmysqlclient_r.so 就建立一個軟連接 ln -s libmysqlclient.so libmysqlclient_r.so
###################################################################################################
yum安裝更為便捷可選
yum -y install MySQL-python #使用yum安裝便不會出現那麼多的包依賴問題了。
Python 的詳細介紹:請點這裡
Python 的下載地址:請點這裡