最近在因课设的要求在研究python,在使用python操作数据库时却碰到如下问题:
1、首先pip install 安装mysql-python时出现的mysql.config地址找不到,google之,通过在环境变量中定义如下变量解决问题:
PATH="/usr/local/mysql/bin:${PATH}"
export PATH
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
JAVA_HOME=`/usr/libexec/java_home`
export JAVA_HOME
2、import Mysqldb 之后 出现“Library not loaded: libmysqlclient.18.dylib ”问题,折腾很久,最后通过如下命令解决:
mkdir -p /usr/local/lib
ln -s /usr/local/mysql/lib/libmysql* /usr/local/lib
$sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib
/Library/Python/2.7/site-packages/_mysql.so