Amazon RDS 中的查询问题
您好,我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 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 thefor
loop to stop the implicit transaction that theSELECT
is running in.我得到了这个问题的解决方案,这是由于Mysql中的隔离级别,我所要做的就是
我为此使用Django,我必须在django数据库设置中添加它
I got the solution to this, it is due to the Isolation level in Mysql, all i had to do was
And i am using Django for this i had to add this in the django database settings