MySQL 슬로우 쿼리 로그 설정

Jmnote (토론 | 기여)님의 2014년 8월 3일 (일) 23:07 판 (→‎실습)
MySQL 슬로우 쿼리 로그 설정
MySQL 느린 쿼리 로그 설정

1 방법

vi /etc/my.cnf
[mysqld]
log-slow-queries = 로그파일명
long_query_time = 시간(초)
→ [mysqld] 아래에 2줄을 추가한다.

2 실습

현재 설정 확인
[root@jmnote ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_allowed_packet=4M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
→ 슬로우 쿼리 설정 없음 확인
로그 폴더 생성
[root@jmnote ~]# mkdir /var/log/mysql
[root@jmnote ~]# chown mysql:mysql /var/log/mysql
[root@jmnote ~]# ll /var/log/ | grep mysql
drwxr-xr-x 2 mysql mysql    4096 Aug  3 22:46 mysql
-rw-r----- 1 mysql mysql   53059 Jun 15 02:08 mysqld.log
로그 설정
[root@jmnote ~]# vi /etc/my.cnf

[mysqld]의 아래 적당한 곳에 다음 내용 기입

long_query_time=3
log-slow-queries=/var/log/mysql/log-slow-queries.log
설정 확인
[root@jmnote ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_allowed_packet=4M
long_query_time=3
log-slow-queries=/var/log/mysql/log-slow-queries.log

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
MySQL 재시작 (설정 적용)
[root@jmnote ~]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

3 테스트

[root@jmnote ~]# mysql -uroot -pP@ssw0rd
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 95
Server version: 5.5.34-log MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

4 같이 보기

5 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}