1、下载MySQL-python-1.2.3b1.tar.gz
解压:tar -zxvf MySQL-python-1.2.3b1.tar.gz
2、使用python setup.py build编译:
Python setup.py build
报错:
mysql_config not found
解决:
whereis mysql
/usr/lib64/mysql /usr/local/bin/mysql /usr/share/mysql /opt/mysql/bin/mysql /opt/mysql-5.7.14-linux-glibc2.5-x86_64/bin/mysql
/opt/mysql/bin/下面有mysql_config,如果没有mysql_config,
请参考文档安装libmysqlclient-dev:http://www.cnblogs.com/afei-qwerty/archive/2017/03/31/6653683.html
修改文件:/opt/soft/python_module/MySQL-python-1.2.3b1/setup_posix.py,第26行,为:/opt/mysql/bin/mysql_config
修改完再执行:
Python setup.py build
ok
3、使用 python setup.py install安装:
python setup.py install
4、在Python下,import MYSQLdb:
报错:
ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory
找不到libmysqlclient.so.20文件,这个文件在/opt/mysql/lib/下面
解决:
64位系统在/usr/lib64/下面建立软连接:
ln -s/opt/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
再次执行:
import MYSQLdb
ok