• 트랜잭션 적용
autocommit 기능 설정
모든 작업에 autocommit 기능을 사용하지 않으려면 autocommit 기능을 비활성화 하면 됨
autocommit 을 비활성화 하는 경우 작업 후 commit 을 하지 않으면 적용되지 않으므로 주의!!
mysql> select @@autocommit;
> autocommit 설정 확인
> 0 은 비활성화, 1은 활성화
mysql> set autocommit=0; 또는 set autocommit=1;
autocommit 설정값 확인
select @@autocommit; # select를 이용한 확인
show variables like 'autocommit'; # show를 이용한 확인
autocommit 설정 또는 해제
| = 임시적으로 autocommit을 설정하는 방법 set autocommit = 1; # autocommit 설정 set autocommit = 0; # autocommit 해제 |
| = 영구적으로 autocommit을 설정하는 방법 /etc/my.cnf 에 [mysqld] 섹션에 넣고 mariadb 데몬을 재시작한다. [mysqld] autocommit = 1 # autocommit 설정, 기본값으로 설정이 없으면 default로 설정 autocommit = 0 # autocommit 해제 |
실습> autocommit 변경하기
현재 설정된 변수중에서 autocommit을 확인한다.
rpm -qa | grep core 라고 의미상 동일하다라고 생각하면 된다.
MariaDB [(none)]> show variables like 'autocommit';
+--------------------------------+-------+
| Variable_name | Value |
+--------------------------------+-------+
| autocommit | ON |
+--------------------------------+-------+
1 rows in set (0.00 sec)
autocommit 변수의 값을 확인한다.
rpm -q coreutils 라고 의미상 동일하다라고 생각하면 된다.
MariaDB [(none)]> select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 1 |
+--------------+
1 row in set (0.00 sec)
Autocommit 기능을 OFF 한다.
MariaDB [(none)]> set autocommit = 0;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 0 |
+--------------+
1 row in set (0.00 sec)
MariaDB [(none)]> show variables like 'autocommit';
+--------------------------------+-------+
| Variable_name | Value |
+--------------------------------+-------+
| autocommit | OFF |
+--------------------------------+-------+
1 rows in set (0.00 sec)
Autocommit 기능을 ON 한다.
MariaDB [(none)]> set autocommit = 1;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 1 |
+--------------+
1 row in set (0.00 sec)
MariaDB [(none)]> show variables like 'autocommit';
+--------------------------------+-------+
| Variable_name | Value |
+--------------------------------+-------+
| autocommit | ON |
+--------------------------------+-------+
1 rows in set (0.00 sec)
COMMIT : 보류중인 모든 데이터 변경사항을 영구적으로 적용하고 현재 트랜잭션을 종료한다.
ROLLBACK : 보류중인 모든 데이터 변경사항을 폐기하고 현재 트랜잭션을 종료한다. 이전의 COMMIT 직후의 단계로 되돌아 간다.
!!! 한마디로 말하면 !!!
COMMIT : 작업 완료
ROLLBACK : 작업 되돌리기 (Undo 기능)
'Linux > SQL' 카테고리의 다른 글
| [DBMS] 변수 실습 (0) | 2021.12.08 |
|---|---|
| [DBMS] 변수(Variable) (0) | 2021.12.08 |
| [DBMS] 트랜잭션 Transaction (0) | 2021.11.30 |
| [DBMS] 뷰 View (0) | 2021.11.30 |
| [DBMS] 유니온 Union (0) | 2021.11.30 |