如何使用mysql.connector禁用查询缓存 [英] How to disable query cache with mysql.connector
问题描述
我正在Kivy应用程序上连接mysql.
I'm connecting mysql on my Kivy application.
import mysql.connector
con = mysql.connector.Connect(host='XXX', port=XXX, user='XXX', password='XXX', database='XXX')
cur = con.cursor()
db = cur.execute("""select SELECT SQL_NO_CACHE * from abc""")
data = cur.fetchall()
print (data)
在从另一个连接中对表abc进行插入或删除之后;我在python上调用了相同的查询;但是数据没有更新.
After inserting or deleting on table abc from another connection; i call the same query on python; but data is not updating.
我添加查询"SET SESSION query_cache_type = OFF;"在选择查询之前,但是没有用.有人说"select NOW()..."查询不可实现,但无法再次使用.我该怎么办?
I add the query "SET SESSION query_cache_type = OFF;" before select query, but it didn't work. Someone said "select NOW() ..." query is not cachable but it didn't work again. What should I do?
推荐答案
我通过在fetchall()之后添加代码解决了这一问题
I solved this with adding the code after fetchall()
con.commit()
在不执行提交的情况下调用相同的选择查询不会更新结果.
Calling the same select query without doing a commit, won't update the results.
这篇关于如何使用mysql.connector禁用查询缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!