4,468,354 th visitor since 2017.2.1 ( Today : 17933 )
Programming
No. 800
Name. swindler
Subject. mysql 이중화 (replication) 처리
Main Cate. MySQL
Sub Cate.
Date. 2018-02-27 17:43
Hit. 1563 (125.131.199.20)
File.
먼저 master와 slave의 my.cnf 파일에 다음과 같이 세팅한다.
server-id 가 같으면 오류난다.


# Master
[mysqld]
server-id = 1
log-bin = mysql-bin

# Slave1
[mysqld]
server-id = 2



master에서 slave에 접속할 사용자를 생성한다.

grant replication slave on *.* to 'repluser'@'10.10.0.11' identified by 'password';


master mysql을 재시작하고, 덤프떠서 데이터를 옮긴다.
master에서 현재 상태를 조회한다.


mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 921 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)



slave에서 다음과 같이 설정한다.
change master to master_host='10.10.0.10', master_user='repluser', master_port=3306, master_password='neulwonpassword', master_log_file='mysql-bin.000001', master_log_pos=921;



그리고 START SLAVE; 를 실행함.
(소문자로는 실행이 안 됨)


그뒤에 master에서 table을 생성하고 insert 등을 해보고 테스트한다.


만약에 정상적으로 작동하지 않으면 다음과 같이 실행한다.

SLAVE STOP;
RESET SLAVE;

change master to ... 실행

SLAVE START;




-------------------------

master와 slave의 UUID가 같으면 오류가 발생한다.

mysql> show variables like '%uuid%';
+---------------+--------------------------------------+
| Variable_name | Value |
+---------------+--------------------------------------+
| server_uuid | 92c68b99-8700-11e3-b32f-002268810529 |
+---------------+--------------------------------------+
1 row in set (0.00 sec)


이럴때는 auto.cnf 파일을 지우고, mysql을 리스타트하면 새로운 UUID가 생성된다.
(auto.cnf파일안에는 UUID 정보말고 아무것도 없음)



[바로가기 링크] : http://coolx.net/cboard/develop/800



Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog