[mysql] binary log 설정

Edward Hyun·2022년 4월 28일
0

backend

목록 보기
70/120

갑작스럽 delete 수행에 의해 복구하는 경우를 대비하여
binary log를 설정하자.

1 먼저 mysql 에서 binary log를 확인할 수 있다.
어드민으로 mysql 접속하고
mysql> sho binary logs;
실행하면 Log_name과 File_size 리스트가 나올 것이다.

2 하지만 conf 파일에 log_bin이 설정되어 있지 않으면 파일 형태로 저장이 안된다. 해당 설정을 해 놓자.
설정파일이 mysql.conf 일수도 있고 mysqld.conf 일수도 있음.
내 경우에는 /etc/mysql/mysql.conf.d/mysqld.cnf 이었음.

find -name '*.apk'
처럼 경로를 생략하고 명령어를 입력하면 해당 디렉토리에서부터 그 하위 디렉토리까지 검색

3 설정을 했으면 mysql를 재시작한다. 로그가 있다면 설정된 폴더에 파일이 생긴다. mysql-bin.00001 이런 식으로

sudo service mysql restart

4 binary log 에서 SQL 추출 방법
mysqlbinlog 유틸을 사용하여 추출함.

mysqlbinlog -d db_name -s mysql-bin.000001 > mysql-bin.000001.sql

-d 뒤에는 DB명을 써주시면 됩니다. -s 옵션은 주석은 제외 한다는 의미 입니다.

참고
mysql 설치경로 확인
ps aux | grep mysql
whereis mysql
기본 설치 경로는 /var/lib/mysql/
저장된 database 경로 확인 방법
mysql> show variables like 'datadir';

출처:
https://eehoeskrap.tistory.com/305
https://stricky.tistory.com/463
https://qucdas.tistory.com/94
https://larva.tistory.com/entry/mysql-설치-경로-확인

profile
앱&웹개발(flutter, vuejs, typescript, react), 인공지능(nlp, asr, rl), 백엔드(nodejs, flask, golang, grpc, webrtc, aws, msa, nft, spring cloud, nest.js), 함수형 프로그래밍(scala, erlang)을 공부하며 정리합니다.

0개의 댓글