[原創]MySQL innodb_rollback_on_timeout參數對鎖的影響

來源:互聯網
上載者:User

標籤:逾時   .com   hle   存在   show   begin   nod   editor   實驗   

環境:Server version:         5.6.21-log MySQL Community Server (GPL)

前提提要:

 

 innodb_rollback_on_timeout是啥作用? 答:事務B在鎖等待逾時後是復原事務內所有的statement還是最後一條語句;      0表示rollback最後一條語句,預設值;有點坑      1表示復原事務B內所有的statements;
此參數是唯讀參數,需在my.cnf中配置,並且重啟生效; 注意:復原statements後不自動commit或rollback事務;坑

表結構:

mysql> show create table t12\G;*************************** 1. row ***************************       Table: t12Create Table: CREATE TABLE `t12` (  `a` int(10) unsigned NOT NULL AUTO_INCREMENT,  `b` varchar(766) DEFAULT NULL,  `c` int(11) DEFAULT NULL,  PRIMARY KEY (`a`),  KEY `b` (`b`)) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin11 row in set (0.00 sec)

 

實驗一:

參數配置:mysql> show variables like ‘innodb_rollback_on_timeout‘;+----------------------------+-------+| Variable_name              | Value |+----------------------------+-------+| innodb_rollback_on_timeout | ON    |+----------------------------+-------+1 row in set (0.00 sec)mysql> show variables like ‘tx_iso%‘;+---------------+-----------------+| Variable_name | Value           |+---------------+-----------------+| tx_isolation  | REPEATABLE-READ |+---------------+-----------------+1 row in set (0.00 sec)mysql> show variables like ‘autocommit‘;+---------------+-------+| Variable_name | Value |+---------------+-------+| autocommit    | ON    |+---------------+-------+1 row in set (0.00 sec)

 過程:

實驗二:

參數配置:mysql> show variables like ‘innodb_rollback_on_timeout‘;+----------------------------+-------+| Variable_name              | Value |+----------------------------+-------+| innodb_rollback_on_timeout | OFF   |+----------------------------+-------+1 row in set (0.00 sec)mysql> show variables like ‘tx_iso%‘;+---------------+-----------------+| Variable_name | Value           |+---------------+-----------------+| tx_isolation  | REPEATABLE-READ |+---------------+-----------------+1 row in set (0.00 sec)mysql> show variables like ‘autocommit‘;+---------------+-------+| Variable_name | Value |+---------------+-------+| autocommit    | ON    |+---------------+-------+1 row in set (0.00 sec)

過程:

 

 總結:

1、關閉innodb_rollback_on_timeout後,一旦以begin;start transaction;等語句開啟一個事務,當鎖等待逾時後,該事務請求的鎖將不釋放,直到事務提交或復原或會話逾時;

所以autocommit參數建議設定成ON,只要程式沒有顯示開啟事務,就可以避免上述鎖未釋放問題。

2、開啟innodb_rollback_on_timeout後,一旦鎖等待逾時,是事務內sql將全部復原,且釋放之前請求的鎖。

3、當autocommit=on,只要不顯示開啟事務,將不存在上面2個問題,即鎖的問題和復原的問題。

 轉載請備忘:http://www.cnblogs.com/su-han/p/6204016.html

[原創]MySQL innodb_rollback_on_timeout參數對鎖的影響

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.