解決 之道問題描述:在mysql的gameshop數(shù)據(jù)庫上操作刪除語句,數(shù)據(jù)庫一直在執(zhí)行,響應(yīng)完后,報Lock wait timeout exceeded;try restarting transaction; 執(zhí)行delete語句刪除失敗。
原因:有會話執(zhí)行過DML操作,然后沒commit提交,再執(zhí)行刪除操作,就鎖了。 __________________________________________________________________________ Lock wait timeout exceeded; try restarting transaction一些信息 1、鎖等待超時。是當(dāng)前事務(wù)在等待其它事務(wù)釋放鎖資源造成的??梢哉页鲦i資源競爭的表和語句,優(yōu)化你的SQL,創(chuàng)建索引等,如果還是不行,可以適當(dāng)減少并發(fā)線程數(shù)。 2、你的事務(wù)在等待給某個表加鎖時超時了,估計是表正被另的進(jìn)程鎖住一直沒有釋放。 可以用 SHOW INNODB STATUS/G; 看一下鎖的情況。 3、搜索解決 之道 在管理 節(jié)點的[ndbd default] 區(qū)加: TransactionDeadLockDetectionTimeOut=10000(設(shè)置 為10秒)默認(rèn)是1200(1.2秒) 4、 InnoDB會自動的檢測死鎖進(jìn)行回滾,或者終止死鎖的情況。 引用 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. 如果參數(shù)innodb_table_locks=1并且autocommit=0時,InnoDB會留意表的死鎖,和MySQL層面的行級鎖。另外,InnoDB不會檢測MySQL的Lock Tables命令和其他存儲引擎死鎖。 你應(yīng)該設(shè)置innodb_lock_wait_timeout來解決這種情況。 innodb_lock_wait_timeout是Innodb放棄行級鎖的超時時間。
|