MySql Row Lock

Spring 2017. 2. 19. 23:14

InnoDB Lock: REF



엔진확인 

   mysql> show engines;

   mysql> show variables;   (autocommit등의  Variables 확인) 



Spring 의 @Transactional과 함께 사용하면 autcommit이 일반적으로는 자동으로 풀렸다가 다시 설정 된다..  REF(Stack-overFlow)  REF



=======================================


Mysql에서 엔진이 innodb(요즘 보통다 이러함)일 경우, row level lock이 지원된다.REF


- start transaction   -> 작업 ->  commit 순으로 수행하면 된다.


start transaction;

select * from sales_item where id=99  lock in share mode;

commit; 



transaction도중에 다른 작업이 또 들어오면

  1. wait이 되거나 (위 REF 참조)

  2. 자동으로 에러가 나서 거절이 되는데..  

(1,2번 중 원하는 데로 선택을 어떻게 하는지 ... 연구 중)



 select for update도 있긴한데.. 한 문장 밖에 안되므로 좀 활용도가 떨어지지만
 spring의 @Transactional과 같이 사용하기에 유리하다.    REF


일단 설정 파일에서
init_connect = 'set autocommit=0'
으로 설정하여 오토커밋을 해제합니다. 기본적으로 mySQL 설치 시엔 오토커밋일 설정되어 있습니다



innodb_lock_wait_timeout 확인 방법.

show variables like '%wait_timeout%';

Posted by yongary
,