Mysql Replication (복제)

1. 서버 정보

IP : 172.20.102.111 (master), 172.20.102.112 (slave)
db : test_db
user : test
pw : test1

2. MASTER 설정

1) DB생성 / 계정생성 / 권한 부여

2) my.cnf
vi /etc/mysql/my.cnf
[mysqld]
log-bin=mysql-bin (바이너리 로그파일 생성경로, log-bin만 기입시 default)
server-id = 1

3) mysql 재시작

3. Master 정보 보기

mysql> show master status; 
 +------------------+----------+--------------+------------------+ 
 | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
 +------------------+----------+--------------+------------------+
 | mysql-bin.000010 |     1    |              |                  | 
 +------------------+----------+--------------+------------------+ 

4. Slave 설정

1) my.cnf
vi /etc/mysql/my.cnf
[mysqld]
server-id=2
replicate-do-db='test_db'

2) database dump
복제할 데이터베이스 master로부터 dump
mysqldump --login-path=test test_db > test.sql (master에서)
mysql --login-path=test < test.sql (slave에서)

3) master 연결
mysql> change master to
 master_host='172.20.102.111',
 master_user='test',
 master_password='test1',
 master_log_file='mysql-bin.000010',
 master_log_pos=1;

4) 재시작

5. 확인

mysql > show processlist \G; (mastser, slave)

mysql > show slave status;

6. UUID 에러
– Slave에서 show slave status; 명령어 입력시 아래와 같은 에러 출력

Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
  • slave에서 auto.cnf를 삭제해주면 된다
systemctl stop mysql
rm -rf /var/lib/mysql/auto.cnf
systemctl start mysql

Published by

shotan

Hi i'm cho

Leave a Reply

Your email address will not be published. Required fields are marked *