gpt4 book ai didi

PHP+MYSQL_locks .....请帮忙.....我被困在这个..?

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

我在 php 中创建了一个文件,并在该文件下编写了一段代码来锁定具有读取模式的表。在那个文件下面,我在同一个表中写了一个插入操作,但是我们知道读锁只支持读操作,这意味着你只能查看表中的内容,但不能修改它。它运行良好。

PROBLEM_EXIST_HERE:我创建了另一个文件,其中包含对同一个表的相同插入操作。这里只写插入操作,不写加锁代码。

在使用此文件之前,我使用 (RUN) 第一个文件(包含锁定+插入)操作,然后我在同一浏览器中打开新选项卡并运行第二个文件(仅包含插入操作)。

既然已经知道读锁已经固定在表上了,那么为什么还要进行插入操作呢?为什么它不向我显示一个错误,指出该表处于 READ 锁定模式,因此无法更新?有人知道如何解决这个问题吗?

  1. 有没有人知道如何知道在 mysql 数据库中一个表是否被锁定在读或写状态?任何人都可以告诉我这个的 php 代码吗?我搜索了一整天,但没有找到解决方案。请用简单的语言编写简单的解决方案。

最佳答案

查看 LOCK TABLE 的文档:

WRITE locks normally have higher priority than READ locks to ensure that updates are processed as soon as possible. This means that if one session obtains a READ lock and then another session requests a WRITE lock, subsequent READ lock requests wait until the session that requested the WRITE lock has obtained the lock and released it.

对于 InnoDB 表,InnoDB 有一个 Lock Monitor :

The InnoDB Lock Monitor is like the standard Monitor but also provides extensive lockinformation. To enable this Monitor for periodic output, create a table named innodb_lock_monitor. 

更多:

The Lock Monitor is the same as the standard Monitor except that it includes additional lock information. Enabling either monitor for periodic output by creating the associatedInnoDB table turns on the same output stream, but the stream includes the extra information if the Lock Monitor is enabled. For example, if you create the innodb_monitor and innodb_lock_monitor tables, that turns on a single output stream. The stream includes extra lock information until you disable the Lock Monitor by removing the innodb_lock_monitor table. 

关于PHP+MYSQL_locks .....请帮忙.....我被困在这个..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12839487/

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