파이썬 pymysql 모듈을 이용하여 실행 중인 스레드 모니터링을 할 수 있다.
- mysql 명령어 : SHOW PROCESSLIST
(DOCS : https://dev.mysql.com/doc/refman/5.5/en/show-processlist.html)
import pymysql
strFormat = '%-10s\t%-10s\t%-20s\t%-20s\t%-30s\t%-10s\t%-30s\t%-30s\t%-10s\n'
strOut = strFormat % ('Id', 'User', 'Host', 'db', 'Command', 'Time', 'State','Info','Progress')
strOut += '----------\t----------\t---------------------\t---------------------\t------------------------------\t' \
'----------\t------------------------------\t------------------------------\t----------\n'
conn = pymysql.connect(host='', user='', password=''
,db='', charset='utf8')
c = conn.cursor()
sql = 'SHOW PROCESSLIST'
c.execute(sql)
rows = c.fetchall()
for i in rows:
strOut += strFormat % (i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])
print(strOut)
c.close()
conn.close()
Id User Host db Command Time State Info Progress
---------- ---------- --------------------- --------------------- ------------------------------ ---------- ------------------------------ ------------------------------ ----------
1 system user None Daemon None InnoDB purge worker None 0.0
2 system user None Daemon None InnoDB purge coordinator None 0.0
3 system user None Daemon None InnoDB purge worker None 0.0
4 system user None Daemon None InnoDB purge worker None 0.0
5 system user None Daemon None InnoDB shutdown handler None 0.0
10 root localhost:47084 information_schema Sleep 583 None 0.0
24 root localhost:47924 mysql Query 0 init SHOW PROCESSLIST 0.0
'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 |
[Python] maria DB 접속 로그 (1) - 설정 및 모니터링 (0) | 2018.05.12 |
MYSQL SHOW PROCESSLIST 명령어 (0) | 2018.05.05 |