有兩種設置方法
第一種在mysql的配置文件中加入,然后重啟mysql
innodb_lock_wait_timeout = 500
第二種直接執行如下命令
set global innodb_lock_wait_timeout=500;
然后重啟mycat和后台微服務,然后觀察是否還有這個報錯
如果懷疑,MYSQL出現死鎖,首先查詢information_schema.innodb_trx表,查看哪些mysql查詢線程ID導致的,但是我查了沒有一直存在的死鎖線程,一般都是鎖幾秒就消失了
如下是引用的網上搜的資料
Error: 1205 SQLSTATE: HY000 (ER_LOCK_WAIT_TIMEOUT)
Message: Lock wait timeout exceeded; try restarting transaction
InnoDB reports this error when lock wait timeout expires. The statement that waited too long was rolled back (not the entiretransaction). You can increase the value of the innodb_lock_wait_timeout configuration option if SQL statements should wait longer for other transactions to complete, or decrease it if too many long-running transactions are causing locking problems and reducing concurrency on a busy system.
翻譯如下:
當鎖等待超時后innodb引擎報此錯誤,等待時間過長的語句被回滾(不是整個事務)。如果想讓SQL語句等待其他事務更長時間之后完成,你可以增加參數innodb_lock_wait_timeout配置的值。如果有太多長時間運行的有鎖的事務,你可以減小這個innodb_lock_wait_timeout的值,在特別繁忙的系統,你可以減小並發。
The length of time in seconds an InnoDB transaction waits for a row lock before giving up. The default value is 50 seconds. A transaction that tries to access a row that is locked by another InnoDB transaction waits at most this many seconds for write access to the row before issuing the following error:
ERROR 1205 (HY000):Lock wait timeout exceeded; try restarting transaction
InnoDB事務等待一個行級鎖的時間最長時間(單位是秒),超過這個時間就會放棄。默認值是50秒。一個事務A試圖訪問一行數據,但是這行數據正在被另一個innodb事務B鎖定,此時事務A就會等待事務B釋放鎖,等待超過innodb_lock_wait_timeout設置的值就會報錯ERROR 1205 (HY000):
於是我嘗試調大innodb_lock_wait_timeout參數:
具體操作:如下可知innodb_lock_wait_timeout是動態參數,默認值50秒,最小值是1秒,最大值是1073741824;
mysql> set GLOBAL innodb_lock_wait_timeout=1500;
(題外話:關於set innodb_lock_wait_timeout=1500; 和 set global innodb_lock_wait_timeout=1500;的區別。前者等價於set session只影響當前session,后者作為全局的修改方式,只會影響修改之后打開的session;注意后者不能改變當前session;)
問題解決