资源不足时要充分发挥主观能动性。
没有测试机的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/python setup.py install
回到MySQL-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 正常