메뉴 건너뛰기

조회 수 117 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

# mysql-bin(binary log)파일 정리 및 삭제 주기 설정 #

linux 에서 mysql 및 mariadb 설치 후 무한정 늘어나느 log-bin 파일에 대해

파일 정리 및 삭제 주기 설정하는 방법에 대하 설명하겠습니다.

mysql-bin 파일은 db 에서 사용된 쿼리들이 로깅되는 파일이며 Innodb 혹은 Replication등에서 사용되곤 합니다.

linux 에서 db 설치 후 db 경로를 따로 지정하지 않는경우 default 경로는

/var/lib/mysql 입니다.

/ 경로 하위이다 보니 갑자기 어느날 / 경로가 말도 안되게 늘어나 있는 경우가 있습니다.

따로 /db 로 파티셔닝을 한 경우도 마찬가지로 log-bin 파일의 저장 기한을 설정하지 않는 이상

log-bin 파일로 인해 용량이 무한정 늘어날 수 있습니다.

[root@localhost mysql]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G  4.0K  1.9G   1% /dev/shm
tmpfs           1.9G   13M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2        42G   11G   32G  26% /
/dev/sda1       497M  173M  324M  35% /boot
tmpfs           378M   40K  378M   1% /run/user/0
[root@localhost mysql]# ll mysql-bin.*
-rw-rw---- 1 mysql mysql     723  3월 16 14:07 mysql-bin.000001
-rw-rw---- 1 mysql mysql 1013906  3월 16 14:07 mysql-bin.000002
-rw-rw---- 1 mysql mysql  179012  3월 16 14:25 mysql-bin.000003
-rw-rw---- 1 mysql mysql  181801  3월 17 10:43 mysql-bin.000004
-rw-rw---- 1 mysql mysql   59803  3월 17 13:44 mysql-bin.000005
-rw-rw---- 1 mysql mysql     365  3월 17 16:31 mysql-bin.000006
-rw-rw---- 1 mysql mysql   59803  3월 23 18:42 mysql-bin.000007
-rw-rw---- 1 mysql mysql   59803  7월 15 16:15 mysql-bin.000008
-rw-rw---- 1 mysql mysql  316828  9월  1 09:51 mysql-bin.000009
-rw-rw---- 1 mysql mysql   12269  9월  1 10:12 mysql-bin.000010
-rw-rw---- 1 mysql mysql   65375  9월  1 10:16 mysql-bin.000011
-rw-rw---- 1 mysql mysql   63141  9월  1 10:27 mysql-bin.000012
-rw-rw---- 1 mysql mysql   59803  9월  3 15:02 mysql-bin.000013
-rw-rw---- 1 mysql mysql   59803  9월  7 13:42 mysql-bin.000014
-rw-rw---- 1 mysql mysql   59803  9월  7 13:53 mysql-bin.000015
-rw-rw---- 1 mysql mysql   63374  9월  7 13:58 mysql-bin.000016
-rw-rw---- 1 mysql mysql   59803  9월  7 14:26 mysql-bin.000017
-rw-rw---- 1 mysql mysql  119241  9월  7 14:37 mysql-bin.000018
-rw-rw---- 1 mysql mysql   80258  9월 14 13:52 mysql-bin.000019
-rw-rw---- 1 mysql mysql     361  9월 14 13:44 mysql-bin.index

mysql-bin 파일은 OS 에서 삭제하는것 보다 mysql 콘솔에서 삭제 하는것이 바람직 합니다.

mysql 에서 제공되는 파일이므로 mysql 콘솔에서 삭제하는것이 깔끔합니다.

db 로 접속 합니다.

[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 184
Server version: 10.2.37-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql
Database changed
MariaDB [mysql]>

mysql 로  접속 후 하기 명령어로 확인 가능 합니다.

MariaDB [mysql]> show binary logs;

MariaDB [mysql]> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       723 |
| mysql-bin.000002 |   1013906 |
| mysql-bin.000003 |    179012 |
| mysql-bin.000004 |    181801 |
| mysql-bin.000005 |     59803 |
| mysql-bin.000006 |       365 |
| mysql-bin.000007 |     59803 |
| mysql-bin.000008 |     59803 |
| mysql-bin.000009 |    316828 |
| mysql-bin.000010 |     12269 |
| mysql-bin.000011 |     65375 |
| mysql-bin.000012 |     63141 |
| mysql-bin.000013 |     59803 |
| mysql-bin.000014 |     59803 |
| mysql-bin.000015 |     59803 |
| mysql-bin.000016 |     63374 |
| mysql-bin.000017 |     59803 |
| mysql-bin.000018 |    119241 |
| mysql-bin.000019 |     80258 |
+------------------+-----------+
19 rows in set (0.00 sec)

전부 다 삭제하려면 제일 마지막 번호까지 입력해 주시면 됩니다.

*ex)purge master logs to 'mysql-bin.000019';

000014 번 이전의 로그만 삭제해 보겠습니다.

MariaDB [mysql]> purge master logs to 'mysql-bin.000014';

MariaDB [mysql]> purge master logs to 'mysql-bin.000014';
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000014 |     59803 |
| mysql-bin.000015 |     59803 |
| mysql-bin.000016 |     63374 |
| mysql-bin.000017 |     59803 |
| mysql-bin.000018 |    119241 |
| mysql-bin.000019 |     80258 |
+------------------+-----------+
6 rows in set (0.00 sec)

삭제 후 매번 삭제를 하기는 귀찮으니 자동 삭제 주기를 설정하겠습니다.

삭제 주기는 시스템 사고가 발생해도 몇일 내에 확인할 수 있거나 특별히 백업해 분석할 것이 아니라면 2주 정도면 충분 합니다.

 

# 보관주기 확인 #

기존 expire_logs_days 가 '0' 이라면 삭제되지 않고 계속 저장이 됩니다.

MariaDB [mysql]> SHOW VARIABLES LIKE '%expire_logs%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 0     |
+------------------+-------+
1 row in set (0.00 sec)

# 보관주기 14일로 변경 후 다시 확인 #

MariaDB [mysql]> set global expire_logs_days=14;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> SHOW VARIABLES LIKE '%expire_logs%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 14    |
+------------------+-------+
1 row in set (0.00 sec)

14일이 지난 파일들은 삭제가 됩니다.

아예 생성하고 싶지 않다면 하기 경로로 들어가 log-bin 경로를 주석처리 해주시면 됩니다.

[root@localhost /]# vi /etc/my.cnf
# log-bin=mysql-bin

 

end.


List of Articles
번호 제목 날짜 조회 수
126 mysql table 값 변경 mariadb 테이블 값 변경 2023.01.12 83
125 FORMAT 문법 사용 하기(숫자 자리수 나타내기) file 2023.01.10 98
124 MYSQL IN&BETWEEN&NULL&예제&FROM절 문제3 file 2021.03.27 104
123 MYSQL any&all&in&예제& WHERE 절 문제4 file 2021.03.27 111
122 CASE 문법 사용 하기 file 2023.01.10 111
121 데이터베이스별 / 테이블별 용량 확인 하기 2023.01.10 115
» mysql-bin(binary log)파일 정리 및 삭제 2023.01.12 117
119 MYSQL Groupby & having 예제 문제 6 file 2021.03.27 118
118 no exists, not in 을 이용한 조건에 만족하지 않는 것들 구하기, 둘의 차이점 2021.03.26 125
117 fulltext 관련 글 2021.03.26 125
116 MYSQL order by 예제&문제 7 file 2021.03.27 126
115 column의 정보 중에서 column 설명(column_comment) 2021.03.26 129
114 binlog 조회 / 삭제 / 보관 기간 설정 file 2023.01.10 129
113 MYSQL FULLTEXT INDEX & PARTION 검색기능향상&파티션 file 2021.03.27 131
112 MYSQL 부속질의어 예제&문제 9 file 2021.03.27 134
111 MYSQL 기초문법&예제&문제 2 file 2021.03.27 136
110 MYSQL 통계 함수 SUM AVG MAX MIN 예제 문제 5 file 2021.03.27 137
109 MYSQL select 명령문의 조합 &union 예제&문제 8 file 2021.03.27 138
108 MariaDB can't create test file lower-test 2023.02.16 139
107 엑셀로 되어있는 부분 db로 import하는 방법 2020.07.28 144
Board Pagination Prev 1 2 3 4 5 6 7 Next
/ 7

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved