Mac 安装MySQL-Python报错问题

python 2.7安装MySQL-Python遇到的问题

ImportError: dlopen(/usr/local/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib Referenced from: /usr/local/lib/python2.7/site-packages/_mysql.so 

操作

sudo install_name_tool -change  libmysqlclient.21.dylib /usr/local/mysql/lib/libmysqlclient.21.dylib /Library/Python/2.7/site-packages/_mysql.so

然后报错

ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Library not loaded: libcrypto.1.0.0.dylib
继续操作
sudo install_name_tool -change libcrypto.1.0.0.dylib  /usr/local/mysql/lib/libcrypto.1.0.0.dylib /Library/Python/2.7/site-packages/_mysql.so

python 3.5安装mysqlclient遇到的问题

pip3 install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "", line 1, in 
      File "/private/var/folders/w6/l9krf1yd1bb_0t3m5bhw_w500000gn/T/pip-build-5ytzox4k/mysqlclient/setup.py", line 18, in 
        metadata, options = get_config()
      File "/private/var/folders/w6/l9krf1yd1bb_0t3m5bhw_w500000gn/T/pip-build-5ytzox4k/mysqlclient/setup_posix.py", line 60, in get_config
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/w6/l9krf1yd1bb_0t3m5bhw_w500000gn/T/pip-build-5ytzox4k/mysqlclient/setup_posix.py", line 60, in 
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/w6/l9krf1yd1bb_0t3m5bhw_w500000gn/T/pip-build-5ytzox4k/mysqlclient/setup_posix.py", line 13, 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 ?

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/w6/l9krf1yd1bb_0t3m5bhw_w500000gn/T/pip-build-5ytzox4k/mysqlclient/

解决办法:

先brew安装mysql-connector

brew install mysql-connector-c

# 修改前先备份

cp  mysql_config mysql_config_backup
# 修改编辑权限
chmod 777 mysql_config
vi mysql_config
# 修改114行
> # Create options 
> libs="-L$pkglibdir"
> libs="$libs -l "
# 修改为
> # Create options 
> libs="-L$pkglibdir"
> libs="$libs -lmysqlclient -lssl -lcrypto"

然后pip3 install mysqlclient


mysqlclient连接数据库时报错:

django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/Cellar/mysql-connector-c/6.1.11/lib/plugin/caching_sha2_password.so, 2): image not found")

解决:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mima'





你可能感兴趣的:(tips)