mysql trouble shooting---- 從庫停止同步lock_wait_timeout_exceeded_try_restarting_transaction

來源:互聯網
上載者:User

標籤:

問題描述:

資料庫從庫停止同步。

 

問題分析:

show slave status\G;(也可使用show full processlist)

顯示 某個update語句出錯,Lock wait timeout exceeded; try restarting transaction; 

原因是這條語句提交的時候逾時堵塞。原因在於另外的一個操作開啟了事務,鎖定了相應的資料,導致這條操作相同資料的sql出錯。

 

樣本,在sql中

(1)開啟事務,鎖定資料

終端A:

MySQL> begin; (開啟事務,開啟事務會鎖定相關資料)
Query OK, 0 rows affected (0.00 sec)

mysql> update pet set sex="m" where name="Fluffy";(修改)
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name   | owner  | species | sex  | birth      | death      |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |
| Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
| Claws  | Gwen   | cat     | m    | 1994-03-17 | NULL       |
| Fang   | Benny  | dog     | m    | 2013-02-05 | NULL       |
| Fluffy | Harold | cat     | m    | 2012-09-30 | NULL       |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.00 sec)

終端B:

mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name   | owner  | species | sex  | birth      | death      |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |
| Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
| Claws  | Gwen   | cat     | m    | 1994-03-17 | NULL       |
| Fang   | Benny  | dog     | m    | 2013-02-05 | NULL       |
| Fluffy | Harold | cat     | NULL | 2012-09-30 | NULL       |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.01 sec)

因為沒有提交,所以實際上沒有改變。但是會鎖定Fluffy這一條資料。導致如下的錯誤。

終端B:

mysql> update pet set sex="m" where name="Fluffy";

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

 

(2)提交事務,解鎖資料

終端A:

mysql> commit;
Query OK, 0 rows affected (0.10 sec)

終端B:

mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name   | owner  | species | sex  | birth      | death      |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |
| Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
| Claws  | Gwen   | cat     | m    | 1994-03-17 | NULL       |
| Fang   | Benny  | dog     | m    | 2013-02-05 | NULL       |
| Fluffy | Harold | cat     | m    | 2012-09-30 | NULL       |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.00 sec)
mysql> update pet set sex="f" where name="Fluffy";
Query OK, 1 row affected (0.08 sec)
Rows matched: 1  Changed: 1  Warnings: 0

 

(3)如果where中的條件是索引欄位,那麼只會鎖定索引對應的條目;如果不是索引欄位,那麼會鎖定整張表。

終端A:

mysql> update pet set sex="f" where death="1995-07-29";
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name   | owner  | species | sex  | birth      | death      |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane  | dog     | f    | 1979-08-31 | 1995-07-29 |
| Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
| Claws  | Gwen   | cat     | m    | 1994-03-17 | NULL       |
| Fang   | Benny  | dog     | m    | 2013-02-05 | NULL       |
| Fluffy | Harold | cat     | f    | 2012-09-30 | NULL       |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.00 sec)

終端B:

mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name   | owner  | species | sex  | birth      | death      |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |
| Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
| Claws  | Gwen   | cat     | m    | 1994-03-17 | NULL       |
| Fang   | Benny  | dog     | m    | 2013-02-05 | NULL       |
| Fluffy | Harold | cat     | f    | 2012-09-30 | NULL       |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.00 sec)
mysql> update pet set death="2013-07-00" where birth="2013-02-05";

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

 

解決辦法

(1) stop slave;      start slave

(2)網上分析說

 

Mysql ‘Lock wait timeout exceeded; try restarting transaction‘ 解決方案

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction 
Temporary error: 266: Time-out in NDB, probably caused by deadlock 解決方案:在管理節點的[ndbd default] 
區加:
TransactionDeadLockDetectionTimeOut=10000(設定為10秒)預設是1200(1.2秒)按照順序重新啟動各個節點就不會出現問題了。

不過,本身貌似資料庫的TransactionDeadLockDetectionTimeOut已經設定很大,而且即使設定很大,如果那邊一直鎖表,也是解決不了問題的。

mysql trouble shooting---- 從庫停止同步lock_wait_timeout_exceeded_try_restarting_transaction

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.