更新查询有时不会更新mySQL数据库中的字段

Emi*_*ily 10 mysql innodb

我有一个mySQL更新查询,有时会更新所有字段,有时它会更新除一个以外的所有字段.

大约10%的电话失败了.

我的表是:

CREATE TABLE IF NOT EXISTS `grades` (   
`id` int(11) NOT NULL AUTO_INCREMENT,   
`state` int(1) NOT NULL,   
`result` varchar(255) NOT NULL,   
`date_synced` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`) ) 
ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4395 ;
Run Code Online (Sandbox Code Playgroud)

我的查询是:

$sqlstr = "UPDATE grades SET result = '$result', state = 2, date_synced = '$date', updated_at = '$date' WHERE id = $id";
Run Code Online (Sandbox Code Playgroud)

失败时,result,date_synced和updated_at会更新,但状态保持不变.

还有另一个查询仅更新状态字段,并且还会间歇性地失败.

我无法在测试环境中重新创建问题.生产mySQL数据库或某种锁定冲突可能有问题吗?


我有更多的信息.我正在使用mysqli.只更新状态的另一个查询是使用mysql.这会导致问题吗?

我以为InnoDB被行锁定了.它不允许部分行更新,是吗?


解决评论的另一个更新.

我的代码流非常线性.

The row is created with state=0.
<flash stuff here> and the row is updated with state=1
A cron job pulls all state=1 and sends an api call
if api call is successful, the row is updated with state=2, result, date_synced, and updated_at
if api call is error, the row is updated with state=3, result, and updated_at
Run Code Online (Sandbox Code Playgroud)

状态字段永远不会设置为0(闪存之后)或1(在api调用之后).由于日期_synced和结果正在设置但是(有时)状态仍为1,这就像正在删除状态字段的更新.

我将添加更新触发器,看看是否能提供更多信息.

Add*_*ons 1

它是否声明“{n} 行受影响?”

另外,它是否可重复?您可以对完全相同的数据运行相同的查询并且它会执行不同的操作吗?

如果是这样,您的安装可能已损坏,或数据库已损坏。

您是否尝试过对桌子进行修复和优化?这可能有帮助。

抱歉,关于铅弹的答案:P