MySQLdb、mysqlclient 和 MySQL 连接器/Python 之间有什么区别? [英] What's the difference between MySQLdb, mysqlclient and MySQL connector/Python?

查看:78
本文介绍了MySQLdb、mysqlclient 和 MySQL 连接器/Python 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在尝试用 python 做一些数据库更新,在设置整个开发环境时,我遇到了这三件让我头晕的事情.

So I've been trying to do some database update with python and while setting up the whole dev environment, I came across these three things which made me dizzy.

  1. MySQLdb

mysqlclient

它们分别是什么、区别以及在何处使用它们?谢谢

What's each of them, the difference and where to use them? Thanks

推荐答案

MySQLdb 是一个围绕 C 模块的薄 python 包装器,它实现了 MySQL 数据库的 API.

MySQLdb is a thin python wrapper around C module which implements API for MySQL database.

前一段时间使用了 MySQLDb1 版本的包装器,现在它被认为是遗留的.随着 MySQLDb1 开始演变为 MySQLDb2 并提供错误修复和 Python3 支持,一个 MySQLDb1 被分叉,这是如何mysqlclient 出现,带有错误修正和 Python3 支持.总而言之,现在我们有尚未准备好用于生产的 MySQLDb2,MySQLDb1 作为过时的驱动程序,以及社区支持的 mysqlclient,具有错误修复和 Python3 支持.

There was MySQLDb1 version of wrapper used some time ago and now it is considered to be a legacy. As MySQLDb1 started evolving to MySQLDb2 with bug fixes and Python3 support, a MySQLDb1 was forked and here is how mysqlclient appeared, with bugfixes and Python3 support. Sum up, so now we have MySQLDb2 which is not ready for production use, MySQLDb1 as an outdated driver and a community supported mysqlclient with bug fixes and Python3 support.

现在,为了解决这个问题,MySQL 提供了自己的 MySQL 适配器版本 - mysql 连接器,一个使用 MySQL API 的全功能 python 模块,没有 C 模块依赖,只使用标准 python 模块.

Now, to solve that mess, MySQL provides their own version of MySQL adapter - mysql connector, an all-in python module that uses MySQL API with no C modules dependencies and only standard python modules used.

所以现在问题归结为:mysqlclient vs mysql connector.

So now the question comes down to: mysqlclient vs mysql connector.

对于我来说,我会选择官方支持的库,但是 mysqlclient 也应该是一个不错的选择.它们都在积极更新修复和新功能,您可以通过最近几天的主动提交看到.

As for me, I would go with officially supported library, however mysqlclient should be a good choice as well. Both of them are being actively updated with fixes and new features which you can see by active commits in last days.

注意:我对它们没有太多经验,因此在某些情况下,它们可能不适合您的需求.这两个库都遵循 PEP-249 标准,这意味着您至少应该没问题基本功能无处不在.

Note: I did not have much experience with them, so there might be cases when one or another does not suite your needs. Both libraries follow PEP-249 standard which means you should be fine with at least base functionality everywhere.

安装和依赖

  • mysqlclient

作为 C 包装器的一个分支,它需要 C 模块与 MySQL 一起工作,MySQL 添加了 python 头文件来构建这些扩展(阅读 python-dev).安装取决于您使用的系统,只需确保您知道软件包名称并可以安装它们即可.

As a fork of C wrapper it requires C modules to work with MySQL which adds python header files to build these extensions (read python-dev). Installation depends on the system you use, just make sure you aware of package names and can install them.

  • mysql connector Main documentation is pretty clear, however you should be aware of Protobuf C++ dependency (for mysql connector versions >= 2.2.3).

这篇关于MySQLdb、mysqlclient 和 MySQL 连接器/Python 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆