Django:在OS X环境下连接MySQL数据库
正常的安装只需要执行以下2条命令:
$ brew install mysql-connector-c
$ pip3 install mysqlclient
但在执行 pip3 install mysqlclient
时,出现报错:
which ()
{
IFS="${IFS= }"; save_ifs="$IFS"; IFS=':'
for file
do
:112
File "<string>", line 1, in <module>
File "/private/var/folders/k9/q3cgwmcx4l51554_97h5rx4h0000gn/T/pip-install-n_ai97oc/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/private/var/folders/k9/q3cgwmcx4l51554_97h5rx4h0000gn/T/pip-install-n_ai97oc/mysqlclient/setup_posix.py", line 63, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/k9/q3cgwmcx4l51554_97h5rx4h0000gn/T/pip-install-n_ai97oc/mysqlclient/setup_posix.py", line 63, in <listcomp>
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/k9/q3cgwmcx4l51554_97h5rx4h0000gn/T/pip-install-n_ai97oc/mysqlclient/setup_posix.py", line 12, in dequote
raise Exception("Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id=86971 ?")
Exception: Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id=86971 ?
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/k9/q3cgwmcx4l51554_97h5rx4h0000gn/T/pip-install-n_ai97oc/mysqlclient/
原因是,MySQL Connector/C使用了错误的默认配置,导致在Mac OS X下编译出错。
因此,解决方法就是修改该默认配置。
执行命令 which mysql_config
以查看配置文件(mysql_config)的具体路径.
$ which mysql_config
/usr/local/bin/mysql_config # 输出了配置文件的真实路径
用你熟悉的编辑器打开该文件, 定位到112行。
#原配置是:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
#修改成以下:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
最后再执行前面的 $ pip3 install mysqlclient
, 已经可以正常安装了。