The default isolation level for MySQL is REPEATABLE READ. If you insert data in shell #1 and issue COMMIT, the data will be available only to newly started transactions after this COMMIT. The transaction in shell #2 was still ongoing and will not see the new data.
You can either change this by setting the default transaction isolation level on the server (or session), or, maybe better, set the isolation for the current transaction.
With MySQL Connector/Python v1.1, setting the isolation is easy using the MySQLConnection.start_transaction()
method. In shell #2, do the following:
>>> cnx = mysql.connector.connect(...)
>>> cnx.start_transaction(isolation_level='READ COMMITTED')
>>> cur = cnx.cursor()
>>> cur.execute("select id, name from sometable where id = 29")
>>> cur.fetchall()
# Do something in shell #1 and commit there
>>> cur.execute("select id, name from sometable where id = 29")
>>> cur.fetchall()
[(28, u'28')]
The start_transaction
is not PEP-249, but you can simply execute the SQL statement START TRANSACTION ISOLATION LEVEL READ COMMITTED
or set the session variable tx_isolation
. But I think the method start_transaction
makes it easier.