MySQL是否(或如何)在本地处理并发事务?

时间:2019-11-24 16:47:49

标签: php mysql concurrency

也许这是一个显而易见的问题,但这只是我不确定的事情。如果我在一个LAMP服务器上运行两个独立的PHP应用程序,并且两个PHP应用程序共享同一个MySQL数据库,那么我是否需要担心并发数据库事务期间的数据完整性,还是MySQL仅在“本机”方面进行处理? ?

如果两个PHP应用程序都尝试同时更新同一记录,会发生什么情况?如果他们尝试同时更新同一张表会怎样?如果他们俩都试图同时从数据库中读取数据,会发生什么?或者,如果一个应用程序尝试在另一应用程序更新该记录的同时读取记录?

1 个答案:

答案 0 :(得分:1)

What happens if the two PHP applications both try to update the same  record at the same time? 

What happens if they try to update the same table at the same time? 

What happens if they both try to read data from the database at the same time? 
Or if one application tries to read a record at the same time as the other application is updating that record?

这取决于几个因素。

您正在使用的数据库引擎

您为您的环境或查询设置的锁定策略/事务     https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html     https://dev.mysql.com/doc/refman/8.0/en/innodb-locks-set.html

您正在使用的代码..您可以使用select进行更新,以仅锁定要修改的行     https://dev.mysql.com/doc/refman/8.0/en/update.html

以及如何管理交易
    https://dev.mysql.com/doc/refman/8.0/en/commit.html

这只是一个简短建议

相关问题