什么是 PyMySQL?它与 MySQLdb 有何不同?它会影响 Django 部署吗?

发布于 2024-12-01 14:42:36 字数 492 浏览 2 评论 0原文

我刚刚使用 PyMySQL 而不是 MySQLdb 解决了 Django 1.3 应用程序中的一些问题。我按照本教程了解如何进行切换: http://web-eng-help.blogspot.com/2010/09/install-mysql-5-for-python-26-and.html

现在我想知道 PyMySQL 到底是什么以及它是如何实现的与 MySQLdb 不同。

我在本地主机上使用它,然后将其上传到某个主机。

在本地主机上使用 PyMySQL 并托管他们提供的任何内容是否可以?由于我已将base.py和introspection.py中的“MySQLdb”更改为“PyMySQL”,更改这些文件后是否需要将其上传到服务器?或者因为它是 Django 的文件,既然 Django 已经上传到那里了,那不是很重要吗?

I just solved some problems in my Django 1.3 app by using PyMySQL instead of MySQLdb. I followed this tutorial on how to make the switch: http://web-eng-help.blogspot.com/2010/09/install-mysql-5-for-python-26-and.html

Now I want to know what PyMySQL actually is and how it is different from MySQLdb.

I am using it on localhost and will then upload it to some hosting.

Is it fine to use PyMySQL on localhost and on hosting whatever they provide? Since I have changed "MySQLdb" in base.py and introspection.py to "PyMySQL", will I need to upload it to the server after changing these files? Or as it is Django's files, since Django will be uploaded there already, does it not matter much?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

肤浅与狂妄 2024-12-08 14:42:37

PyMySQL 和 MySQLdb 都是 Python 的数据库连接器,是使 Python 程序能够与 MySQL 服务器通信的库。

部署应用程序时,您通常不会上传核心 Django 文件。如果 Django 在您的部署服务器上运行良好,那么您绝对不需要在那里进行任何更改。 DB 驱动程序甚至比 ORM 低一两步,当然您编写的任何代码都不取决于正在使用的代码。

PyMySQL and MySQLdb are both database connectors for Python, libraries to enable Python programs to talk to a MySQL server.

You would normally never upload core Django files when deploying an app. If Django is working fine on your deployment server, you definitely don't need to change anything there. The DB driver is a step or two below the ORM even, and certainly none of the code you have written depends on which of these is in use.

懒猫 2024-12-08 14:42:37

你的第一点:

根据 pymysql wiki 页面:

MySQLdb 是一个 C 扩展模块,享有盛誉
很难编译,尤其是在 Mac 上。此外,
最终用户需要等待为每个新版本编译新的二进制文件
Python 版本,MySQLdb 永远不会在 Jython、IronPython 上运行,
或 PyPy(没有 cpyext 或 IronClad 之类的东西)。我们还维护
Python 2 和 Python 3 之间 100% 兼容,因此所有进步
在 2.x 主干上制作的代码将立即在 Python 3 上可用。

你的第二点:

如果 django 在你的本地主机上工作正常,那么它在
你的发展。

Your first point:

According to pymysql wiki page:

MySQLdb, is a C extension module that has a reputation of being
difficult to compile, especially if you're on a Mac. Additionally,
end-users need to wait for new binaries to be compiled for each new
release of Python, and MySQLdb will never run on Jython, IronPython,
or PyPy (without something like cpyext or IronClad). We also maintain
100% compatibility between Python 2 and Python 3, so all advancements
made on the 2.x trunk will be immediately available on Python 3.

Your second point:

If django is working fine on your localhost, then it should be fine on
your development.

雨巷深深 2024-12-08 14:42:37

根据我的经验,我在安装“MySQL-python”-(MySQLdb)时遇到了困难。
它让我寻找更多的替代品,所以我找到了 pymysql,它也很容易安装,并且在第一个 go 中工作得非常顺利。
所以我建议仅使用 pymysql 而不是 MySQLdb。

As per my experience I had difficulty in installing "MySQL-python" - (MySQLdb).
It made me search for more alternatives so I found pymysql, and it also got installed easily and worked in first go like a charm.
So I would suggest using pymysql only instead of MySQLdb.

我是男神闪亮亮 2024-12-08 14:42:37

我从这些主题开始,我只想说一个观察:PyMSQL 有 CPYTHON 作为要求(可能是为了性能而可选https://pypi.org/project/PyMySQL/#requirements)来安装,并且Cpyhton依赖于'C',我测试了Cpython,在安装C版本时遇到了麻烦太...那么两个实现都依赖于“C”[如果你想要性能],对我来说是一样的...如果性能不是问题,也许PyMySQL在没有Cpython的情况下很好,没有“C”。也许我们可以从 PyMySQL 单独使用 Python 开始,然后将 Python 切换到 Cpython 以获得性能,这可能是一件好事,我们让所有东西都在运行,之后我们可以尝试切换到 Cpython,,,
我们需要知道功能差异。为什么在 Django PyMySQL 中为你运行得更好或者给你一些问题的解决方案,什么问题?这也许是变革的重要内容。 MySQLdb 可能直接依赖于“C”,但 PyMSQL 间接通过 Cpython(在性能相似的情况下),我更喜欢直接依赖而没有跳转限制...问候。

I am starting with these topic, I only want to say an observation: PyMSQL has CPYTHON as a requirement(is optionall perhaps for performance https://pypi.org/project/PyMySQL/#requirements) to install, and Cpyhton depend on 'C', I tested Cpython and I had trouble when installed for the version of C too... then both implementation depend on 'C' [if you want performance], is the same thing for me...if the performance is not problem, perhaps PyMySQL is good without Cpython, free of 'C'. Perhaps we can start with PyMySQL alone with Python and switch Python to Cpython to gain in performance that could be a good thing we have all the things running and after that we can try to switch to Cpython,,,
We need to know the funcionality difference. Why in Django PyMySQL run better for you or give to you solutions for some problems, what problems? That is the important thing for change perhaps. MySQLdb perhaps depend directly from 'C' but PyMSQL indirectly thru Cpython(in case of similar performance), I prefer a direct dependence without limitations of jumps...Greetings.

メ斷腸人バ 2024-12-08 14:42:36

PyMySQL 和 MySQLdb 提供相同的功能 - 它们都是数据库连接器。区别在于 MySQLdb 是 C 扩展而 PyMySQL 是纯 Python 的实现。

尝试 PyMySQL 有几个原因:

  • 在某些系统上运行可能更容易
  • 它与 PyPy 一起使用
  • 它可以“绿色化”并与 gevent 一起使用

在 Django 中使用它的正确方法是导入它并告诉它模拟MySQLdb 在你的顶级文件中,通常是manage.py。将以下代码放在manage.py(或启动服务器时调用的任何文件)的最顶部:

try:
    import pymysql
    pymysql.install_as_MySQLdb()
except ImportError:
    pass

PyMySQL and MySQLdb provide the same functionality - they are both database connectors. The difference is in the implementation where MySQLdb is a C extension and PyMySQL is pure Python.

There are a few reasons to try PyMySQL:

  • it might be easier to get running on some systems
  • it works with PyPy
  • it can be "greened" and works with gevent

The proper way to use it with Django is to import it and tell it to impersonate MySQLdb in your top-level file, usually manage.py. Put the following code at the very top of your manage.py (or whatever file you call when starting your server):

try:
    import pymysql
    pymysql.install_as_MySQLdb()
except ImportError:
    pass
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文