Php 这是Mysql Bug?;关于选择。。。对于更新锁定模式X插入意图
有一个表结构是id,aid。。。。。。aid是一个索引(int的一种类型) 这个错误不能在PHP中抛出,在PHP和MySQL中没有错误。只需自动回滚,然后继续执行其他代码 更改MySQL查询顺序如下:Php 这是Mysql Bug?;关于选择。。。对于更新锁定模式X插入意图,php,mysql,laravel-5,mysql-5.7,Php,Mysql,Laravel 5,Mysql 5.7,有一个表结构是id,aid。。。。。。aid是一个索引(int的一种类型) 这个错误不能在PHP中抛出,在PHP和MySQL中没有错误。只需自动回滚,然后继续执行其他代码 更改MySQL查询顺序如下: trx1 and 2: begin; trx1: select max(id) ... for update; trx1: insert ...; trx2: select max(id) ... for update; trx1: commit; the trx2 result is curre
trx1 and 2: begin;
trx1: select max(id) ... for update;
trx1: insert ...;
trx2: select max(id) ... for update;
trx1: commit; the trx2 result is currectly
我的MySql版本是5.7
我被看见了(同样类型的问题):这是: 对于以下测试代码:
//prepared:
CREATE TABLE `test_lock` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`aid` int(11) NOT NULL,
`otherinfo` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `aid` (`aid`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
insert into `test_lock` (`aid`) values(10);
##trx1 and trx2
begin;
##trx1
select max(id) from `test_lock` where (`aid` = 10) limit 1 for update;
##trx2(have blocked)
select max(id) from `test_lock` where (`aid` = 10) limit 1 for update;
##trx1
insert into `test_lock` (`aid`) values(10);
##then trx2 will gave a deadlock error and look that error
show engine innodb status\G;
使用PHP进行测试(我使用Laravel5.6命令):
在PHP文件2中,结果为空。没有任何错误抛出。没有mysql错误日志。
您可以使用显示引擎innodb状态\G;发现僵局发生了
有什么方法可以给我帮助吗?即使我不知道如何停止PHP程序即使我不知道如何停止PHP程序
//prepared:
CREATE TABLE `test_lock` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`aid` int(11) NOT NULL,
`otherinfo` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `aid` (`aid`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
insert into `test_lock` (`aid`) values(10);
##trx1 and trx2
begin;
##trx1
select max(id) from `test_lock` where (`aid` = 10) limit 1 for update;
##trx2(have blocked)
select max(id) from `test_lock` where (`aid` = 10) limit 1 for update;
##trx1
insert into `test_lock` (`aid`) values(10);
##then trx2 will gave a deadlock error and look that error
show engine innodb status\G;
//file1:
$aid = 10;
DB::beginTransaction();
$result = DB::table('test_lock')->where('aid', $aid)->orderByDesc('id')->lockForUpdate()->first();
var_dump($result);
echo "after get:" . date('Y-m-d H:m:s.u'). "\r\n";
sleep(10); // wrong
DB::table('test_lock')->insert(
['aid' => $aid]
);
echo "after insert:" . date('Y-m-d H:m:s.u'). "\r\n";
//sleep(10); // correctly and file2 is correct result
DB::commit();
//file2
$aid = 10;
DB::beginTransaction();
$pdo = DB::connection()->getPdo();
$result = DB::table('test_lock')->where('aid', $aid)->orderByDesc('id')->lockForUpdate()->first();
var_dump($result); //NULL
echo "after get:" . date('Y-m-d H:m:s.u'). "\r\n";
var_dump($pdo->errorCode()); // 00000
$ret = DB::table('test_lock')->insert(
['aid' => $aid]
);
echo "after insert:" . date('Y-m-d H:m:s.u'). "\r\n";
DB::commit();