Mysql如何解决死锁问题
创始人
2024-12-20 16:21:58
0次

show engine innodb status\G    

  1. *** (1) TRANSACTION:

  2. TRANSACTION 8631FDC, ACTIVE 0 sec inserting

  3. mysql tables in use 2, locked 2

  4. LOCK WAIT 7 lock struct(s), heap size 1248, 107 row lock(s)

  5. MySQL thread id 28162, OS thread handle 0x7f4ab3073700, query id 210340529 tc-demo-dev3.dfengg.com 172.16.2.173 root

  6. INSERT INTO Text****(BusinessId,Type,Template,CreatedUserId,LastModifiedUserId,Delivery,DeliveryWindow,BusinessCalendar) SELECT 124001698, 205, '[CustomerFirstName], your next appointment with [Business] is [AppointmentDateTime]. We look forward to seeing you at your upcoming appointment.', 0, 0, IFNULL(96, Delivery),DeliveryWindow,BusinessCalendar FROM Text**** WHERE BusinessId=0 AND Type=205

  7. *** (1) WAITING FOR THIS LOCK TO BE GRANTED:

  8. RECORD LOCKS space id 794567 page no 6 n bits 88 index `PRIMARY` of table `df1`.`Text****` trx id 8631FDC lock_mode X insert intention waiting

  9. Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0

  10.  0: len 8; hex 73757072656d756d; asc supremum;;

  11.  

  12. *** (2) TRANSACTION:

  13. TRANSACTION 8631FDB, ACTIVE 0 sec setting auto-inc lock

  14. mysql tables in use 2, locked 2

  15. 5 lock struct(s), heap size 1248, 106 row lock(s)

  16. MySQL thread id 28158, OS thread handle 0x7f4a48cd0700, query id 210340528 tc-demo-dev3.dfengg.com 172.16.2.173 root

  17. INSERT INTO Text****(BusinessId,Type,Template,CreatedUserId,LastModifiedUserId,Delivery,DeliveryWindow,BusinessCalendar) SELECT 124001699, 406, 'Dear [CustomerFirstName],\n\nYou have an upcoming appointment with [BusinessName]. Please take a minute to review the details of your appointment scheduled for:\n\n[AppointmentDateTime]\n\nIf you are unable to make this appointment, it is important that you call us at [BusinessPhone] as soon as possible so we can make other arrangements.\n\nWe look forward to seeing you at your upcoming appointment.\n\nSincerely,\n\n[BusinessName]\n[BusinessPhone]\n[BusinessEmail]\n[BusinessWebsite]\n\n-----\nThis email provided by Demandforce, Inc. To unsubscribe, please click this link:\n\n[UnsubscribeLink]\n\n', 0, 0, IFNULL(504, Delivery),DeliveryWindow,BusinessCalendar FROM Text**** WHERE BusinessId=0 AND Type=406

  18. *** (2) HOLDS THE LOCK(S):

  19. RECORD LOCKS space id 794567 page no 6 n bits 88 index `PRIMARY` of table `df1`.`Text****` trx id 8631FDB lock mode S

  20. Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0

  21.  

  22. .................................

  23.  

  24. *** (2) WAITING FOR THIS LOCK TO BE GRANTED:

  25. TABLE LOCK table `df1`.`Text****` trx id 8631FDB lock mode AUTO-INC waiting

  26. *** WE ROLL BACK TRANSACTION (2)

分析: 

 1)insert .... select ...语句,在MYSQL里,会对select ...涉及的所有记录进行锁定,这是特殊的select加X锁的情况,原因是为保证数据的一致性(M-S环境),假设不锁定,在执行过程中,select 包含的表一直在做插入操作,那么M端select出来的记录数就会比S端少,数据就会不一致。   2)查看select的执行计划   点击(此处)折叠或打开

  1. mysql> explain SELECT 124001698, 205, '[CustomerFirstName], your next appointment with [Business] is [AppointmentDateTime]. We look forward to seeing you at your upcoming appointment.', 0, 0, IFNULL(96, Delivery),DeliveryWindow,BusinessCalendar FROM Text**** WHERE BusinessId=0 AND Type=205;

  2. +----+-------------+---------------------+------+---------------+------+---------+------+------+-------------+

  3. | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

  4. +----+-------------+---------------------+------+---------------+------+---------+------+------+-------------+

  5. | 1 | SIMPLE | Text**** | ALL | NULL | NULL | NULL | NULL | 6108 | Using where |

  6. +----+-------------+---------------------+------+---------------+------+---------+------+------+-------------+

  7. 1 row in set (0.00 sec)

key=null,rows=6108 全表扫描,没有可用的索引。   解决办法: 在BusinessId,Type字段建复合索引。   通过索引1)可以更快的定位数据2)锁定更少的行。

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...