存庫報錯 (1205, 'Lock wait timeout exceeded; try restarting transaction')

今天檢查數據庫時,發現比之前爬取的數據少了很多,查看日誌,發現數據庫不停報錯,報錯代碼

(1205, 'Lock wait timeout exceeded; try restarting transaction')

大批量錯誤圖片:

錯誤原因:有會話執行過DML操作,然後沒commit提交,再執行刪除操作,就鎖了。

Lock wait timeout exceeded; try restarting transaction一些信息

1、鎖等待超時。是當前事務在等待其它事務釋放鎖資源造成的。可以找出鎖資源競爭的表和語句,優化你的SQL,創建索引等,如果還是不行,可以適當減少併發線程數。

2、你的事務在等待給某個表加鎖時超時了,估計是表正被另的進程鎖住一直沒有釋放。
可以用 SHOW INNODB STATUS/G; 看一下鎖的情況。

3、搜索解決 之道
在管理 節點的[ndbd default]
區加:
TransactionDeadLockDetectionTimeOut=10000(設置 爲10秒)默認是1200(1.2秒)

4、

    InnoDB會自動的檢測死鎖進行回滾,或者終止死鎖的情況。


引用
InnoDB automatically detects transaction deadlocks and rolls back a transaction or transactions to break the deadlock. InnoDB tries to pick small transactions to roll back, where the size of a transaction is determined by the number of rows inserted, updated, or deleted.


如果參數innodb_table_locks=1並且autocommit=0時,InnoDB會留意表的死鎖,和MySQL層面的行級鎖。另外,InnoDB不會檢測MySQL的Lock Tables命令和其他存儲引擎死鎖。 你應該設置innodb_lock_wait_timeout來解決這種情況。 innodb_lock_wait_timeout是Innodb放棄行級鎖的超時時間。