보통 용량 확보를 위해 Binary Log 삭제해야 할 경우가 있습니다.

mysql 디렉토리 가보면 막 00001 00002 00003.. 삭제하고 싶은 파일들이 보이는데요

수동 삭제하지 말고, MySQL 내에서 purge 로 삭제해 주어야 합니다. 


해당 바이너리 로그 보관은 expire_logs_days 에서 조절할 수 있습니다

( mysql> show variables like 'expire%'; 로 확인 하고, 

set globa; expire_logs_days=일수; 로 설정 ) 

단 set global 은 데몬 재구동시 설정 초기화되므로, 

값 업데이트 또는 my.cnf 설정 하세요. 

root@Web1:/usr/local/mysql/var# mysql -u root -p      권한자 로그인

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 5.1.67-log Source distribution


Copyright (c) 2000, 2012, 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> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

+--------------------+

3 rows in set (0.00 sec)


mysql> use mysql;

Database changed

mysql> show binary logs;              로그 리스트 보기

+------------------+-----------+

| Log_name         | File_size |

+------------------+-----------+

| mysql-bin.000012 |       149 |

| mysql-bin.000013 |       149 |

| mysql-bin.000014 |       106 |

+------------------+-----------+

3 rows in set (0.00 sec)


mysql> purge master logs to 'mysql-bin.000013';   000013 제외한 "이전" 의 바이너리 로그 모두 삭제. 

Query OK, 0 rows affected (0.03 sec)


mysql> show binary logs;

+------------------+-----------+

| Log_name         | File_size |

+------------------+-----------+

| mysql-bin.000013 |       149 |    13 이전의 12가 삭제 됌. 

| mysql-bin.000014 |       106 |

+------------------+-----------+

2 rows in set (0.00 sec)


mysql> show variables like 'expire%';    바이너리 로그 보관기간 확인

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| expire_logs_days | 2     |

+------------------+-------+

1 row in set (0.00 sec)


mysql> set global expire_logs_days=2;    설정은 set global 로 가능. 

Query OK, 0 rows affected (0.00 sec)


모든 작업 후에는 혹시 모르니 flush privileges; 를 해주는 버릇을 들여보자.



블로그 이미지

늙은M군

개인 저장공간입니다. 해당 일부 과정들을 공인 인터넷 환경에서 악성적으로 응용할 시 피해가 발생할 수 있으며, 그에 대해 책임은 사용자에게 있습니다!! 주의해주세요.

,