|
小二货_ 发表于 2015-1-21 17:37 ![]()
我的意思是,set autocommit=0 ,即使不加上for update,也是有锁表的功能
session 1
mysql> set autocommit = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> show create table test1\G
*************************** 1. row ***************************
Table: test1
Create Table: CREATE TABLE `test1` (
`id` int(10) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> update test1 set id =30;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 12 Changed: 0 Warnings: 0
session 2
mysql> update test1 set id =30;
mysql> select * from information_schema.innodb_locks\G
*************************** 1. row ***************************
lock_id: 9658866:192:3:2
lock_trx_id: 9658866
lock_mode: X
lock_type: RECORD
lock_table: `test`.`test1`
lock_index: GEN_CLUST_INDEX
lock_space: 192
lock_page: 3
lock_rec: 2
lock_data: 0x000001E00900
*************************** 2. row ***************************
lock_id: 9658865:192:3:2
lock_trx_id: 9658865
lock_mode: X
lock_type: RECORD
lock_table: `test`.`test1`
lock_index: GEN_CLUST_INDEX
lock_space: 192
lock_page: 3
lock_rec: 2
lock_data: 0x000001E00900
2 rows in set (0.00 sec) |
|