<p>您可以执行以下步骤,如果您的系统中已经安装了brew和MySQL,请跳过步骤1和步骤2:</p>
<h3>第一步:安装Brew</h3>
<p>您需要在本地计算机中安装<a href="https://brew.sh/" rel="nofollow noreferrer">Homebrew</a>。您可以通过:</p>
<pre class="lang-sh prettyprint-override"><code>/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
</code></pre>
<h3>步骤Twp:安装MySQL</h3>
<p>使用<strong>自制</strong>您可以通过以下方法安装<strong>mysql</strong>:</p>
^{pr2}$
<p>然后使用以下命令在MySQL server中设置凭据:</p>
<pre class="lang-sh prettyprint-override"><code>mysql_secure_installation
</code></pre>
<p>最后,如果要在登录时启动并作为后台服务,请运行以下命令:</p>
<pre class="lang-sh prettyprint-override"><code>brew services start mysql
</code></pre>
<p>其他</p>
<pre class="lang-sh prettyprint-override"><code>mysql.server start
</code></pre>
<h3>第三步:安装MySQL-Connector-C</h3>
<p>要将任何其他应用程序连接到MySQL,您需要安装一个连接器。你可以这样做:</p>
<pre class="lang-sh prettyprint-override"><code>brew install mysql-connector-c
</code></pre>
<p>然后根据<a href="https://pypi.org/project/mysqlclient/" rel="nofollow noreferrer">mysqlclient's</a>文档,您需要在<code>mysql_config</code>处进行错误修复。对于终端中的第一个类型<code>mysql_config</code>:</p>
<pre class="lang-sh prettyprint-override"><code>>> mysql_config
Usage: /usr/local/bin/mysql_config [OPTIONS]
Compiler: ...
</code></pre>
<p>{cd1>你需要在哪里找到它。然后您可以使用您喜欢的任何编辑器,并在<code>mysql_config</code>中更改以下行:</p>
<p>改变</p>
<pre class="lang-sh prettyprint-override"><code># on macOS, on or about line 112:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
</code></pre>
<p>到</p>
<pre class="lang-sh prettyprint-override"><code># Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
</code></pre>
<h3>第四步:安装XCode Select</h3>
<p>您可以通过以下方式实现:</p>
<pre class="lang-sh prettyprint-override"><code>xcode-select install
</code></pre>
<h3>第五步:安装OpenSSL</h3>
<p>请运行以下命令:</p>
<pre class="lang-sh prettyprint-override"><code>brew install openssl
</code></pre>
<p>然后使用以下行添加到环境的路径:</p>
<pre class="lang-sh prettyprint-override"><code>export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
</code></pre>
<h3>第六步:断开MySQL的链接并链接MySQL-Connector-C</h3>
<p>您需要取消mysql的链接并链接mysql-connector-c</strong>:</p>
<pre class="lang-sh prettyprint-override"><code>brew unlink mysql
brew link overwrite mysql-connector-c
</code></pre>
<h3>第七步:安装MySQLClient</h3>
<p>您应该能够在没有任何错误的情况下使用<code>pip install mysqlclient</code>。在</p>
<h3>第八步:再次链接MySQL</h3>
<p>现在,您需要执行第六步的相反操作:</p>
<pre class="lang-sh prettyprint-override"><code>brew unlink mysql-connector-c
brew link overwrite mysql
</code></pre>
<p>希望现在<code>mysqlclient</code>可以正常工作,并且将应用程序从mysql连接到django没有问题。在</p>
<p>仅供参考,我在<a href="https://ruddra.com/posts/install-mysqlclient-macos/" rel="nofollow noreferrer">this blog post</a>中也写了同样的东西。在</p>