標籤:逾時 .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參數對鎖的影響