Amazon RDS 中的查询问题

发布于 2024-11-09 09:07:52 字数 423 浏览 0 评论 0原文

您好,我有一个 python 脚本,可以连接到 Amazon RDS 计算机并检查新条目。 我的脚本在本地主机上完美运行。但在 RDS 上它不会检测到新条目。一旦我取消脚本并再次运行,我就会得到新的条目。为了测试,我尝试了这样的方法

cont = MySQLdb.connect("localhost","root","password","DB") 
cursor = cont.cursor() 
for i in range(0, 100):
    cursor.execute("Select count(*) from box")
    A = cursor.fetchone()
    print A 

,在此过程中,当我添加新条目时,它不会检测到新条目,但当我关闭连接并再次运行它时,我会得到新条目。为什么我检查了缓存,它是 0。我还缺少什么。

Hi i have a python script that connects to an Amazon RDS machine and check for new entries.
my scripts works on the localhost perfectly. But on the RDS it does not detect the new entry. once i cancel the script and run again i get the new entry. For testing i tried it out like this

cont = MySQLdb.connect("localhost","root","password","DB") 
cursor = cont.cursor() 
for i in range(0, 100):
    cursor.execute("Select count(*) from box")
    A = cursor.fetchone()
    print A 

and during this process when i add a new entry it does not detect the new entry but when i close the connection and run it again i get the new entry. Why is this i checked the cache it was at 0. what else am i missing.

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

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

发布评论

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

评论(2

明月夜 2024-11-16 09:07:52

我在 MySQL 命令行客户端中也看到过这种情况。

我的理解(来自链接到此 URL 的其他人)是 Python 的 API 经常默默地创建事务: http://www.python.org/dev/peps/pep-0249/

如果这是真的,那么即使在另一个事务添加行之后,您的光标也会查看数据的一致版本。您可以尝试在 for 循环中执行 cursor.rollback() 来停止 SELECT 正在其中运行的隐式事务。

I have seen this happen in MySQL command-line clients as well.

My understanding (from other people linking to this URL) is that Python's API often silently creates transactions: http://www.python.org/dev/peps/pep-0249/

If that is true, then your cursor is looking at a consistent version of the data, even after another transaction adds rows. You could try doing a cursor.rollback() in the for loop to stop the implicit transaction that the SELECT is running in.

葬﹪忆之殇 2024-11-16 09:07:52

我得到了这个问题的解决方案,这是由于Mysql中的隔离级别,我所要做的就是

Set the default transaction isolation level transaction-isolation = READ-COMMITTED

我为此使用Django,我必须在django数据库设置中添加它

'OPTIONS': {
                "init_command": "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"
                }

I got the solution to this, it is due to the Isolation level in Mysql, all i had to do was

Set the default transaction isolation level transaction-isolation = READ-COMMITTED

And i am using Django for this i had to add this in the django database settings

'OPTIONS': {
                "init_command": "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"
                }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文