# MySQL error&#x20;

{% hint style="info" %}
응용프로그램 : MySQL Error 로그와 Slow-Query 로그 취합을 위한 설정
{% endhint %}

### 1. 응용프로그램 로그 수집 설정

1-1. 설정 경로

* [시스템 > 시스템 관리](https://docs.plura.io/ko/function/common/system/management) > 대상 선택 > 설정 탭 이동 > 설정 버튼을 클릭합니다.

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/1.png" alt="" width="563"><figcaption></figcaption></figure>

1-2. 응용프로그램 원본로그 수집 설정 활성화

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/2.png" alt="" width="563"><figcaption></figcaption></figure>

1-3. 경로 > 설정 버튼 클릭

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/3.png" alt="" width="563"><figcaption></figcaption></figure>

1-4. 태그 선택 및 경로 입력

* MySQL Error 로그와 Slow-Query 로그 경로를 입력합니다.

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/4.png" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/5.png" alt="" width="563"><figcaption></figcaption></figure>

1-5. 입력 정보 확인

* 태그가 정상적으로 등록되었는지 확인 후, 수정 버튼을 클릭합니다.

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/6.png" alt="" width="563"><figcaption></figcaption></figure>

* 태그 등록 방법
  * 응용 프로그램 로그 수집 설정을 위한 태그를 등록할 수 있습니다.
  * 경로 : [관리 > 목록](https://docs.plura.io/ko/function/common/management/list) > 응용프로그램 태그

* 설정 버튼을 클릭합니다.

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/7.png" alt="" width="563"><figcaption></figcaption></figure>

* 등록 버튼을 클릭하여 등록하고자 하는 태그를 입력합니다.

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/8.png" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/9.png" alt="" width="563"><figcaption></figcaption></figure>

###

***

### 2. MySQL – SLOW QUERY 설정 <a href="#id-2" id="id-2"></a>

2.1 설정

```bash
vi /etc/my.cnf
```

```
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql-slow.log
long_query_time = 3
```

2.2 로그 파일 생성 및 권한 설정

```bash
touch /var/log/mysql-slow.log
chown mysql.mysql /var/log/mysql-slow.log
```

2.3 권한 확인

```bash
ls -aZ /var/log/mysql*
```

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/10.png" alt=""><figcaption></figcaption></figure>

2.4 mysql restart

```bash
systemctl restart mysqld
```

2.5 활성화 확인

```bash
mysql> show variables like ‘slow_query_%’;
```

<figure><img src="https://qubitsec.github.io/docs/images/Ins_G/mysql_slow/11.png" alt=""><figcaption></figcaption></figure>

2.6 mysql query 로깅 추가(선택)

```bash
vi /etc/my.cnf
```

```
[mysqld]
general_log_file = /var/log/general.log
general_log = 1
```

```bash
touch /var/log/general.log
chown mysql.mysql /var/log/general.log
systemctl restart mysqld
```

2.7 권한 문제로 로그 기록이 되지 않는 경우 safe start

```bash
./mysqld_safe &
```

### 3. 로그 확인 <a href="#id-3" id="id-3"></a>

* Mysql Error 또는 Slow Query 로그 발생 후 응용프로그램 로그에서 MySQL 관련 로그를 확인합니다.\
  등록한 태그명으로 검색이 가능합니다.

### 참고 매뉴얼 <a href="#id-4" id="id-4"></a>

> [https://docs.plura.io/ko/faq/comm/uploadapp](https://docs.plura.io/ko/faq/common/uploadapp)
