start two independent transactions with mysql

668 views Asked by At

I want to recreate a dirty read anomaly with two independent transactions. I've started the terminal twice and connected both with my database. I've started the transaction with the command start transaction; in both. Then I updated one information in the first terminal window and this is what it showed me: Rows matched: 1 Changed: 1 Warnings: 0. After selecting all data in this table the change was there. But as I tried to show the changed data select * from adress; in the second terminal window, it didn't show me the change but the old data.

In the end I need to prove the dirty read anomaly and avoid this happening with the right isolation level.

Here are two screenshots of my terminal windows.

Transaction 1:

transaction 1

Transaction 2:

transaction 2

What am I doing wrong?

Thanks for the help, Robin

1

There are 1 answers

0
Ajwhiteway On

You need to commit the changes on your first transaction

https://dev.mysql.com/doc/refman/5.7/en/commit.html

The idea of a transaction is to allow you to do a series of operations that either all must be successful, or they all mustn't happen.

Hope that helps.