1. maria DB 로깅설정
set global general_log = 1;
set global log_output = 'TABLE';
show variables where Variable_name in ('version', 'log' , 'general_log')
2. 접속로그 확인 쿼리
select * from general_log where command_type = 'Connect'
3. 파이썬(python)을 이용한 접속로그 출력
import pymysql
conn = pymysql.connect(host='ip', user='root', password='password',db='mysql', charset='utf-8')
c = conn.cursor()
c.execute('select * from general_log where command_type = "Connect"')
rows = c.fetchall()
strOut = ''
strFormat = '%-20s\t%-30s\t%-20s\t%-20s\t%-20s\t%-20s\n'
strOut = strFormat % ('event_time', 'user_host', 'thread_id', 'server_id', 'command_type', 'agument')
strOut += '--------------------\t------------------------------\t--------------------\t--------------------\t--------------------\t--------------------'
print(strOut)
for i in rows:
i = list(map(str,i))
strOut = strFormat % (i[0][:19],i[1],i[2],i[3],i[4],i[5])
print(strOut, end='')
4. 활용
- 일 단위로 로그를 받아서 접속로그를 파일 또는 다른 DB로 저장. (보안증적)
- maria db 날짜쿼리의 활용하여 모니터링
'Mysql, Maria DB' 카테고리의 다른 글
[ mariadb query ] delete문 (0) | 2019.11.29 |
---|---|
maria db today sql (오늘 날짜 출력 쿼리) (0) | 2019.09.30 |
[Python] pandas를 이용한 mariadb 결과값 csv 파일로 저장 (0) | 2019.08.26 |
maria db column 추가 (0) | 2019.07.22 |
CentOS mariadb slow query (슬로우쿼리) 설정 (0) | 2019.07.05 |
python을 이용한 maria DB 접속 로그 (1) - grafana 시각화 모니터링 (0) | 2019.06.10 |
MYSQL SHOW PROCESSLIST 명령어 (0) | 2018.05.05 |
[Python] mysql lock monitoring. (실행 중인 스레드 모니터링) (0) | 2018.05.05 |