什么是 PyMySQL?它与 MySQLdb 有何不同?它会影响 Django 部署吗?
我刚刚使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
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.
你的第一点:
根据 pymysql wiki 页面:
你的第二点:
Your first point:
According to pymysql wiki page:
Your second point:
根据我的经验,我在安装“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.
我从这些主题开始,我只想说一个观察: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.
PyMySQL 和 MySQLdb 提供相同的功能 - 它们都是数据库连接器。区别在于 MySQLdb 是 C 扩展而 PyMySQL 是纯 Python 的实现。
尝试 PyMySQL 有几个原因:
在 Django 中使用它的正确方法是导入它并告诉它模拟MySQLdb 在你的顶级文件中,通常是manage.py。将以下代码放在manage.py(或启动服务器时调用的任何文件)的最顶部:
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:
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):