728x90
목차
1. 트랜잭션 개념
2. 락(lock)
3. 격리수준(Isolation)

1. 트랜잭션 개념

트랜잭션(Transaction)

  • 복수의 SQL문을 수행하는 도중(예: 은행 간의 이체)에 장애가 발생했을 때 장애에 대응할 수 있도록 하는 기능
  • 전체 수행(커밋:Commit)과 전체 취소(롤백:Rollback) 두 가지의 결과값만 가져야 함
  • 기본적으로 SQL의 수행모드는 AutoCommit모드(줄단위 커밋모드)
  • 트랜잭션을 지원하기 위해서는 AutoCommit모드를 오프시켜야 함
  • InnoDB 스토리지엔진만 가능함

ACID특성

  • 원자성(Atomicity)
  • 일관성(Consistency)
  • 고립성/격리수준(Isolation)
  • 지속성(Durability)

데이터베이스 트랜잭션

  • 트랜잭션 기본 설정 확인
  • AutoCommit 설정 끄기(줄단위 커밋모드 취소)
  • 트랜잭션 커밋/롤백하기
select @@autocommit; (1=true / 0=fasle)
set autoCommit = false;
create database sampleDB;
create table BusinessCard(Name Varchar(255), Address Varchar(255), Telephone Varchar(255));
insert into BusinessCard values(‘Bob’, ‘Seocho-dong 123’, ‘123-4567’);
commit; or rollback;

 

2.락(Lock)

락(Lock)

  • 공유자원(리소스)에 대해 여러 개의 트랜잭션이 접근하려고 경쟁하려고 할 때 제어하는 방법
  • 일관성(Consistency)과 무결성(Integrity)을 지키기 위해서 적용
  • Lock Granularity
select engine, support from information_schema.engines where support=‘DEFAULT’;
set default_storage_engin=InnoDB;
set default_storage_engine=MyISAM;
select engine from information_schema.TABLES where table_name = ‘city’ and table_schema=‘world’;
alter table ‘city engine = InnoDB; (주의)

 

2. 격리(Isolation)

트랜잭션의 격리수준(Isolation Level)

  • 트랜잭션에 일관성 없는 데이터를 허용하는 레벨

—> Read Committed와 Serializable의 중간이 Repeatable Read

select @@tx_isolation;
set tx_isolation = ’READ-COMMITED’;
commit;
728x90

'IT > SQL' 카테고리의 다른 글

MySQL[20] - 대용량 데이터베이스 구축 기술  (0) 2022.06.23
MySQL[19] - 저장 프로시저, 트리거  (0) 2022.06.23
MySQL[17] - Full Text Search, Bulk Insert  (0) 2022.06.14
[SQL] 프로시저 vs 함수  (0) 2022.06.14
[SQL] 기본 요소  (0) 2022.06.06

+ Recent posts