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

查看:83
本文介绍了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开始发展为具有错误修复和Python3支持的 MySQLDb2 ,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连接器,这是一个全功能的python模块,它使用具有 无C模块依赖项 且仅使用标准python模块的MySQL API.

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一起使用,该模块添加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天全站免登陆