[MySQL] 데이터베이스 복제(DUMP import & export)

leeng·2024년 6월 23일
0

1. mysql 환경변수 설정

우선 mysql 환경변수가 설정이 안 되어 있는 경우에 환경변수부터 설정해준다.
아래는 macOS 기준이고, mysql의 bin 파일 경로도 다를 수 있으니 확인 후 설정해주자.

  • vi ~/.bash_profile
  • export PATH="/usr/local/mysql/bin:$PATH" 입력
  • source ~/.bash_profile
  • mysql —version 실행해보기

2. Dump 파일 생성

mysqldump -u root -p 복제하려는 데이터베이스 > dump 파일명.sql ;
명령어 실행 후 password를 입력한다.
현재 경로가 아닌 특정 경로에 덤프 파일을 생성하고 싶으면 파일명 앞에 경로도 넣어주면 된다.
ex) mysqldump -u root -p 복제하려는 데이터베이스 > /mypath/mysql/dump 파일명.sql ;

3. Dump 파일 import

우선 Import하려는 대상 데이터베이스를 생성해준다.

mysql -u root -p 대상 데이터베이스 < 덤프파일.sql 명령어로 import한다.

확인해보면 잘 import 되어 있다.


사실 mysql은 Dbeaver에서 도구 > Dump or Restore database 기능으로 덤프 뜨고 덤프 import 하는 것도 간단하다. 처음에 local client 설정해주고 몇 가지 에러만 핸들링하면 잘 된다.

참고로 디비버에서 덤프 진행할 때 겪었던 에러와 해결법은 아래와 같다.

  • @@GLOBAL.GTID_PURGED cannot be changed: the added gtid set must not overlap with @@GLOBAL.GTID_EXECUTED 에러

    -> mysql 콘솔에서 reset master;

  • This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable 에러

    mysql 콘솔에서 SET GLOBAL log_bin_trust_function_creators = 1;

profile
기술블로그보다는 기록블로그

0개의 댓글