Python's MySqlDB not getting updated row

后端 未结 2 486
庸人自扰
庸人自扰 2020-12-03 08:12

I have a script that waits until some row in a db is updated:

con = MySQLdb.connect(server, user, pwd, db)

When the script starts the row\'

相关标签:
2条回答
  • 2020-12-03 09:02

    This is an InnoDB table, right? InnoDB is transactional storage engine. Setting autocommit to true will probably fix this behavior for you.

    conn.autocommit(True)
    

    Alternatively, you could change the transaction isolation level. You can read more about this here: http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html

    The reason for this behavior is that inside a single transaction the reads need to be consistent. All consistent reads within the same transaction read the snapshot established by the first read. Even if you script only reads the table this is considered a transaction too. This is the default behavior in InnoDB and you need to change that or run conn.commit() after each read.

    This page explains this in more details: http://dev.mysql.com/doc/refman/5.0/en/innodb-consistent-read.html

    0 讨论(0)
  • 2020-12-03 09:15

    I worked around this by running

    c.execute("""set session transaction isolation level READ COMMITTED""")
    

    early on in my reading session. Updates from other threads do come through now.

    In my instance I was keeping connections open for a long time (inside mod_python) and so updates by other processes weren't being seen at all.

    0 讨论(0)
提交回复
热议问题