gpt4 book ai didi

php - MySQL 本身是否(或者如何)处理并发事务?

转载 作者:行者123 更新时间:2023-11-29 09:29:24 25 4
gpt4 key购买 nike

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

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

最佳答案

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

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

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

这只是一个简短的建议

关于php - MySQL 本身是否(或者如何)处理并发事务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59020050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com