【无标题】

记录一次Mac中已安装mysqlclient的报错及解决

在这里插入图片描述

在安装mysqlclient时,或者已经安装后还是无法启动django项目

django.core.exceptions.ImproperlyConfigured: Error  loading MySQLdb module.
Did you install mysqlclient?

解决办法

  1. 使用homebrew安装mysql-client
    brew install mysql-client@8.4
    
  2. 配置好环境变量
    # 使用的是8.4版本的,需要修改mysql-client为mysql-client@8.4
    echo 'export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
    echo 'export LDFLAGS="-L/opt/homebrew/opt/mysql-client/lib"' >> ~/.zshrc
    echo 'export CPPFLAGS="-I/opt/homebrew/opt/mysql-client/include"' >> ~/.zshrc
    source ~/.zshrc
    

出现认证方法不对,依旧无法连接mysql

  1. 出现错误
    django.db.utils.OperationalError: (2059, "Authentication plugin 'mysql_native_password' cannot be 
    loaded:dlopen(/opt/homebrew/Cellar/mysqlclient/9.0.1/lib/plugin/mysql_native_password.so, 0x0002): 
    tried: '/opt/homebrew/Cellar/mysql-client/9.0.1/lib/plugin/mysql_native_password.so' (no such file), 
    '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/mysql-client/9.0.1/lib/plugin/mysql_native_password.so' (no such file), 
    '/opt/homebrew/Cellar/mysql-client/9.0.1/lib/plugin/mysql_native_password.so' (no such file)")
    
    原因是MySQL客户端在尝试加载mysql_native_password插件时失败了,安装小于9.0版本的mysql-clietn
    brew install mysql-client@8.4
    

pkg-config

  1. 如果在安装时出现
    Can not find valid pkg-config name. Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually [end of output]
    
    则是表明在构建mysqlclient时,无法找到有效的pkg-config,使用homebrew安装对应包
    brew install pkg-config
    

Homebrew太慢,brew换国内源,推荐清华源

在macOS上,您可以通过更改Homebrew的源来加速软件包的下载速度。以下是更改Homebrew源的步骤:

  1. 备份现有的Homebrew源
    首先,备份现有的Homebrew源,以防需要恢复:

    cd "$(brew --repo)"
    git remote -v
    
  2. 更改Homebrew的主仓库源
    将Homebrew的主仓库源更改为国内镜像源,例如清华大学的镜像源:

    git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
    
  3. 更改Homebrew Core仓库源
    将Homebrew Core仓库源更改为国内镜像源:

    git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-core" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
    
  4. 更改Homebrew Cask仓库源
    将Homebrew Cask仓库源更改为国内镜像源:

    git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
    
  5. 更新Homebrew
    更改源后,更新Homebrew以应用更改:

    brew update
    
  6. 验证更改
    验证更改是否生效:

    git -C "$(brew --repo)" remote -v
    git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-core" remote -v
    git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" remote -v
    

以上 lee分享

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

li-xun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值