先裝python,因爲系統已有python,將python安裝至home目錄下;java
修改home目錄下.bash_profile文件,添加python/bin路徑到PATH中;python
添加MySQLdb,遇到不少問題,如下內容裝載自 http://tobeno1.javaeye.com/blog/799242mysql
##########################################linux
linux 安裝mysqldb:
1. 建立/usr/local/python
2.複製setuptools-0.6c11-py2.6.egg到/usr/local/python
3.執行sh setuptools-0.6c11-py2.6.egg
4.複製MySQL-python-1.2.3.tar.gz到當前目錄
5.解壓
6.修改site.cfg中的mysql_config,改爲mysql安裝目錄下的mysql_config路徑,如:/usr/local/mysql/mysql/bin/mysql_config
7.執行python setup.py build
8.執行python setup.py install
9.成功後,執行import MySQLdb,當作功否,通常來講,這時候不成功的錯誤以下:
mysqldb安裝出錯:
1.zipimport.ZipImportError: can't decompress data; zlib not available
解決辦法從新編譯一下Python源碼安裝包,以下:
1 tar jxvf Python-2.5.2.tar.bz2 2 cd Python-2.5.2/
3 ls
4 sudo ./configure 5 gvim Modules/Setup
6 sudo gvim Modules/Setup
在這裏把454行左右的 找到
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
去掉註釋
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
而後從新編譯,安裝python
2.ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
#解決方法
#updatedb
#locate libmysqlclient_r.so.16
/usr/local/mysql-5.1.30-linux-i686-glibc23/lib/libmysqlclient_r.so.16.0.0
/usr/local/mysql-5.1.30-linux-i686-glibc23/lib/libmysqlclient_r.so.16
/usr/local/mysql/lib/mysql/libmysqlclient_r.so.16
/usr/local/mysql/lib/mysql/libmysqlclient_r.so.16.0.0
#vi /etc/ld.so.conf
在ld.so.conf中加入:
/usr/local/mysql/lib/mysql/
#ldconfig -v
再次測試,成功!sql
##########################################vim