MySql事务死锁

Deadlock found when trying to get lock; try restarting transaction(尝试获取锁时发现死锁;尝试重新启动事务)

insert/update不要使用下面写法

/*insert*/
insert into personalrecordinfo (PersonalSignUpId,`Explain`) select PersonalSignUpId`Explain` from personalrecordinfo where !locate('报名',`Explain`)
/*update*/
update personalsignin set IsChangCustomer=1 where PersoanlInfoId=10252 and CustomerId=21 and CompanyId=71 and ViewDate='2022-09-09'

insert改成查询出符合条件的数据,再循环添加;update改成查询出符合条件的数据,再根据主键循环修改(尽量根据主键修改)。

虽然我真的觉得非常麻烦,明明可以一句话解决的事情,非要分成两步。

记录一下相关sql语句

/*查看最近死锁的日志*/
show engine innodb status
/*查看正在进行中的事务*/
SELECT * FROM information_schema.INNODB_TRX
/*解除死锁*/
show processlist

 

posted @ 2022-09-09 11:49  MuZiLily  阅读(112)  评论(0编辑  收藏  举报