<p><a href="http://mysql-python.sourceforge.net/MySQLdb.html" rel="noreferrer">MySQLdb</a>是一个围绕C模块的瘦python包装器,它实现了针对MySQL数据库的API。</p>
<p>很久以前有一个<a href="https://github.com/farcepest/MySQLdb1" rel="noreferrer">MySQLDb1</a>版本的包装器,现在它被认为是一个遗留的。当MySQLDb1开始演变成<a href="https://github.com/farcepest/moist" rel="noreferrer">MySQLDb2</a>并支持bug修复和Python3时,MySQLDb1被分叉,这里是<a href="https://github.com/PyMySQL/mysqlclient-python" rel="noreferrer">mysqlclient</a>如何出现的,并支持bug修复和Python3。综上所述,现在我们有了尚未准备好投入生产使用的MySQLDb2,MySQLDb1是一个过时的驱动程序,还有一个社区支持的mysqlclient,它提供了bug修复和Python3支持。</p>
<p>现在,为了解决这个问题,MySQL提供了自己版本的MySQL适配器-<a href="https://dev.mysql.com/doc/connector-python/en/connector-python-introduction.html" rel="noreferrer">mysql connector</a>,这是一个使用MySQL API的all-in-python模块,没有C模块依赖关系,只使用标准python模块。</p>
<p>所以现在的问题归结为:mysqlclient与mysql connector。</p>
<p>至于我,我会选择官方支持的库,但是<code>mysqlclient</code>也应该是一个不错的选择。
这两个版本都在使用修复程序和新功能进行主动更新,您可以通过前几天的主动提交看到这些功能。</p>
<p><em>注意:我对它们没有太多的经验,所以可能会有这样或那样的情况不符合您的需要。这两个库都遵循<a href="https://www.python.org/dev/peps/pep-0249/" rel="noreferrer">PEP-249</a>标准,这意味着您应该可以在任何地方至少使用基本功能。</em></p>
<p><strong>安装和依赖项</p>
<ul>
<li>mysqlclient公司</li>
</ul>
<p>作为C包装的一个分支,它需要C模块与MySQL一起工作,MySQL添加了python头文件来构建这些扩展(read python dev)。安装取决于您使用的系统,只需确保您知道软件包名称并可以安装它们。</p>
<ul>
<li>mysql连接器
<a href="https://dev.mysql.com/doc/connector-python/en/connector-python-installation.html" rel="noreferrer">Main documentation</a>很清楚,但是您应该知道<a href="https://developers.google.com/protocol-buffers/docs/downloads" rel="noreferrer">Protobuf C++</a>依赖关系(对于mysql连接器<a href="https://github.com/sanpingz/mysql-connector" rel="noreferrer">versions >= 2.2.3</a>)。</li>
</ul>