728x90
반응형
MySQL 로그 설정 정보 확인
Mysql에 접속 되어 실행 되는 SQL 들을 확인 할수 있는 방법에 대해 공유 하겠습니다.
Mysql DB 에 먼저 접속 한후 로그깅 설정 정보를 확인 합니다.
- SHOW VARIABLES 명령을 통해 Mysql 에 현재 적용된 로그레벨과 로그 파일 위치를 확인 합니다.
SHOW VARIABLES LIKE '%general%';
- 실행 결과
mysql> SHOW VARIABLES LIKE '%general%';
+------------------+---------------------------------+
| Variable_name | Value |
+------------------+---------------------------------+
| general_log | ON |
| general_log_file | /var/lib/mysql/24a15adb0cb3.log |
+------------------+---------------------------------+
2 rows in set (0.45 sec)
+------------------+---------------------------------+
| Variable_name | Value |
+------------------+---------------------------------+
| general_log | ON |
| general_log_file | /var/lib/mysql/24a15adb0cb3.log |
+------------------+---------------------------------+
2 rows in set (0.45 sec)
- 로그확인(tail -f general_log_file )
- mysql db에 수행된 sql 에 대해서 조회가 가능 합니다.
2023-03-07T10:29:12.676978Z 103 Query show tables
2023-03-07T10:29:28.580687Z 103 Query SELECT DATABASE()
2023-03-07T10:29:37.020534Z 103 Query show databases
2023-03-07T10:29:45.540610Z 103 Query SELECT DATABASE()
2023-03-07T10:29:45.540744Z 103 Init DB book_db
2023-03-07T10:29:45.541425Z 103 Query show databases
2023-03-07T10:29:45.541874Z 103 Query show tables
2023-03-07T10:29:45.542875Z 103 Field List Book_book
2023-03-07T10:29:45.749166Z 103 Field List Book_book_voter
2023-03-07T10:29:45.773772Z 103 Field List auth_group
2023-03-07T10:29:45.822584Z 103 Field List auth_group_permissions
2023-03-07T10:29:45.848494Z 103 Field List auth_permission
2023-03-07T10:29:45.889815Z 103 Field List auth_user
2023-03-07T10:29:45.977628Z 103 Field List auth_user_groups
2023-03-07T10:29:46.019426Z 103 Field List auth_user_user_permissions
2023-03-07T10:29:46.038964Z 103 Field List django_admin_log
2023-03-07T10:29:46.047558Z 103 Field List django_content_type
2023-03-07T10:29:46.187867Z 103 Field List django_migrations
2023-03-07T10:29:46.208062Z 103 Field List django_session
2023-03-07T10:29:51.093263Z 103 Query show tables
2023-03-07T10:30:02.581078Z 103 Query select * From auth_user
2023-03-07T10:30:08.757684Z 103 Query select * From auth_user
2023-03-07T10:30:24.740727Z 103 Query select * from Book_book
2023-03-07T10:30:57.684327Z 103 Query SET GLOBAL general_log = 'OFF'
2023-03-07T10:29:28.580687Z 103 Query SELECT DATABASE()
2023-03-07T10:29:37.020534Z 103 Query show databases
2023-03-07T10:29:45.540610Z 103 Query SELECT DATABASE()
2023-03-07T10:29:45.540744Z 103 Init DB book_db
2023-03-07T10:29:45.541425Z 103 Query show databases
2023-03-07T10:29:45.541874Z 103 Query show tables
2023-03-07T10:29:45.542875Z 103 Field List Book_book
2023-03-07T10:29:45.749166Z 103 Field List Book_book_voter
2023-03-07T10:29:45.773772Z 103 Field List auth_group
2023-03-07T10:29:45.822584Z 103 Field List auth_group_permissions
2023-03-07T10:29:45.848494Z 103 Field List auth_permission
2023-03-07T10:29:45.889815Z 103 Field List auth_user
2023-03-07T10:29:45.977628Z 103 Field List auth_user_groups
2023-03-07T10:29:46.019426Z 103 Field List auth_user_user_permissions
2023-03-07T10:29:46.038964Z 103 Field List django_admin_log
2023-03-07T10:29:46.047558Z 103 Field List django_content_type
2023-03-07T10:29:46.187867Z 103 Field List django_migrations
2023-03-07T10:29:46.208062Z 103 Field List django_session
2023-03-07T10:29:51.093263Z 103 Query show tables
2023-03-07T10:30:02.581078Z 103 Query select * From auth_user
2023-03-07T10:30:08.757684Z 103 Query select * From auth_user
2023-03-07T10:30:24.740727Z 103 Query select * from Book_book
2023-03-07T10:30:57.684327Z 103 Query SET GLOBAL general_log = 'OFF'
MySQL 로그 설정 변경
- set global general_log 명령을 통해 로그를 on/off 시킬수도 있습니다.
- 해당 명령을 수행한 이후에는 flush logs 명령을 수행 해주세요
SET GLOBAL general_log = 'OFF';
FLUSH LOGS ;
SET GLOBAL general_log = 'ON';
728x90
반응형
'05.DB > Mysql' 카테고리의 다른 글
[Mysql] 유저 생성 /DB생성/권한부여 (0) | 2022.05.24 |
---|---|
[Mysql] DBeaver Mysql 접속 (0) | 2022.04.19 |