MySQL Lock wait timeout exceeded

强颜欢笑 提交于 2020-02-03 08:06:28

问题


I have got the error Lock wait timeout exceeded; try restarting transaction. What are the reasons for this and how to solve the problem? FYI: innodb_lock_wait_timeout = 100 in MySQL config file.


回答1:


This is problem of lock contention, which ultimately result in a time-out on one of the lock. Here are a few suggestions:

  • Make sure you have the correct indexes which result in row-level locks not table-level lock. This will reduce the contention.
  • Make sure you have indexes on the foreign key constraints. To check the relational constraints during insert or update, some database lock the whole referenced table if there is no such index (don't know if this is the case of MySQL)
  • If problem is still here, try to make the transaction faster/smaller. Again, this will reduce the contention on the database.
  • Increase the timeout but keep the value reasonable



回答2:


Is this happening on a high-trafficked system where transactions take a long time (i.e. tables are locked for a long time)? If so, you might want to look into your transaction code to make them shorter / more granular / more performant.



来源:https://stackoverflow.com/questions/2099857/mysql-lock-wait-timeout-exceeded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!