我的 python 脚本中有两个 mysql 连接。例子:
conn1 = mdb.connect(server, user, pw, db)
conn2 = mdb.connect(server, user, pw, db)
#1. then, I execute "select" sql command to select table A by conn1,
#2. after that, I execute "update" sql command to update table A by conn2,
#3. finally, I execute "select" sql command again to select table A by conn1,
但最后,#3 的结果与#1 相同;但是,在#2 之后,我看到数据在 mysql 工作台中更新。
有人知道为什么#3 无法获得最新数据吗?
以下是我的python代码:
import MySQLdb as mdb
import time
conn1 = mdb.connect(SERVER, USER, PASSWORD, DB)
cur1 = conn.cursor()
count1 = cur.execute("SELECT trigger_time FROM trigger_set WHERE id=1")
data1 = cur.fetchall()
cur1.close()
print data1
conn2 = mdb.connect(SERVER, USER, PASSWORD, DB)
cur2 = conn2.cursor()
cur2.execute("update trigger_set set trigger_time = '2013/8/30 17:15' where id=1")
conn2.commit()
cur2.close()
cur1 = conn.cursor()
count1 = cur.execute("SELECT trigger_time FROM trigger_set WHERE id=1")
data1 = cur.fetchall()
print data1