Can't see inserted data from MySQL immediately

你。 提交于 2021-02-07 10:24:11

问题


I am using JDBC.My test application inserts some data into MySQL,then query it via the same connection.I have four computers,one is MySQL server,three are UBuntu Desktops.In one UBuntu Desktop,my test application run into this problem,but I don't find this problem in other UBuntu Desktops. Also,If I create a new connection to query data after inserting,I can find the data.The version of mysql-connector-java library is 5.1.17.I tried 5.1.18,but the problem still exists.


回答1:


The default isolation level for MySQL is "REAPEATABLE READ", that means if you are not using autocommit in your query tool, you will not see committed data from other transactions unlesse you end your own transaction by issuing a COMMIT or ROLLBACK.

The fact that you can see the data after creating a new connection also points into that direction.

So you have two options

  1. change the isolation level for your "query" connections to "READ COMMITTED"
  2. issue a COMMIT (or ROLLBACK) in your query tool before running the SELECT


来源:https://stackoverflow.com/questions/7655824/cant-see-inserted-data-from-mysql-immediately

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!