資源不足時要充分發揮主觀能動性。
沒有測試機的root許可權,但想用python指令碼對資料庫進行壓測,只能在自己的目錄下安裝。所以configure的--prefix以及後來install MySQLdb時的路徑選項很重要。
1.
Python tar xvf Python-2.6.5.tar.bz2
cd Python-2.6.5
./configure --prefix=your_python_dir
make && make instal
2.
MySQLdb tar xzvf MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
vi site.cfg 修改mysql_config=your_mysql_dir/mysql-bin/bin/mysql_config
Your_python_dir/bin/python setup.py build
Your_python_dir/bin/python setup.py install --prefix=you_python_dir
這一步可能會提示
ImportError: No module named setuptools
3.
setuptool tar xzvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
Your_python_dir/bin/python
setup.py build
Your_python_dir/bin/
py
thon setup.py install
回到
MySQ
L-python-1.2.3c1目錄,執行安裝MySQLdb最後一步:
Your_python_dir/bin/python setup.py install --prefix=you_python_dir
4.
import MySQLdb 報錯 ImportError: libmysqlclient_r.so.16:
cannot open shared object file: No such file or directory
解決:Find ~ -name "libmysqlclient_r.so.16" 動態庫在
you_mysql_dir/mysql-bin/lib/mysql 下
cd ~ && vi .bashrc
增加export LD_LIBRARY_PATH="your_mysql_dir/mysql-bin/lib/mysql$LD_LIBRARY_PATH"
重啟session,import MySQLdb 正常
謝謝cat
、小洪
。