SW Engineer & Developer/Python Craft
Django MariaDB AutoCommit
ByteCraft
2025. 1. 29. 09:37
Session 레벨에서 autocommit 설정을 변경할 때는, 아래의 구문을 사용한다.
• autocommit 설정값 확인
show variables like 'autocommit%';
• autocommit 설정 또는 해제
SET AUTOCOMMIT = TRUE; --> 설정
SET AUTOCOMMIT = FALSE; --> 해제
• 트랜잭션 commit, rollback
COMMIT;
ROLLBACK;
그리고 DB의 기본 autocommit 설정을 변경하기 원한다면, 아래의 설정을 추가해주면 된다.
• /etc/my.cnf.d/server.cnf
[mysqld]
autocommit=0 --> autocommit 해제
#settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', #DB 엔진
'NAME': 'ezpodb', #DB 이름
'USER': 'XXXX', #DB User
'PASSWORD': 'XXXX', #비밀번호
'HOST': 'localhost', #HOST
'PORT': '3306', #PORT
'OPTIONS': {
'autocommit': True, #AutoCommit설정
'charset': 'utf8', #utf8설정
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
},
'ATOMIC_REQUESTS': True, #요청 단위로 트랜잭션 처리
}
}
'ATOMIC_REQUESTS': True, # 요청 단위로 트랜잭션 처리
- REST API에서 CRUD가 되려면, 이 옵션을 추가 해야 함.
MariaDB 기본 설정은 'autocommit': Flase임.
- python manage.py createsuperuser
- 이 명령으로 superuser가 생성되지 않아, 'autocommit': True 추가 해봄. But, 안됨.(조만간 해결하자!)