기본 콘텐츠로 건너뛰기

MySQL Replication

First Configuration

  • Master Server

    -- create user for replication
    GRANT REPLICATION SLAVE ON *.* TO 'replusr'@'XXX.XXX.XXX.XXX' IDENTIFIED BY 'replpwd';
    -- check user
    select user, host from mysql.user where user = 'replusr';
    
    RESET MASTER;
    -- Locking for start sync
    FLUSH TABLES WITH READ LOCK;
    -- check all task was flushed
    SHOW STATUS LIKE 'Key_blocks_not_flushed';
    /*
    Key_blocks_not_flushed | 0 
    */
    
    -- get file name and position
    SHOW MASTER STATUS\G;
    /*
    File: mysql-bin.000001
    Position: 999
    */
    
  • Master check sync

    mysql -u root -p -e "SHOW ENGINE INNODB STATUS\G" | grep -e "Log sequence number" -e "Log flushed up to"
  • Master backup

    mysqldump -u root -p --all-databases >all-databases.dmp
  • Slave conf

    STOP SLAVE;
    RESET SLAVE ALL;
    -- using master file and position
    CHANGE MASTER TO 
    MASTER_HOST='XXX.XXX.XXX.XXX',
    MASTER_USER='replusr',
    MASTER_PASSWORD='replpwd',
    MASTER_LOG_FILE='mysql-bin.000001',
    MASTER_LOG_POS=999;
    
    UNLOCK TABLES;
    -- check slave
    SHOW SLAVE STATUS\G

BinaryLog

Bin-log need for replication configuration.

  • vi /etc/my.cnf
    [mysqld]
    # enable binary log
    log-bin=mysql-bin
    server-id=1001
    # set expire bin-log
    expire_logs_days=14
    
  • SQL
    -- show bin-log files
    SHOW MASTER STATUS;
    -- delete under mysql-bin.000989
    PURGE MASTER LOGS TO 'mysql-bin.000990';

Check

  • Master
show master status;
-- Check Master position
-- if null, this server is slave or stand-alone
  • Slave
show slave status;
-- Check master position and slave position
-- You can see result on master and slave

Reconnect

  • If replication is broken and reconnect
/* on Slave
*/
show slave status;
-- get Master_Log_file
-- get Exec_Master_Log_Pos

STOP SLAVE;

RESET SLAVE;

CHANGE MASTER TO MASTER_LOG_FILE='<Master_Log_file>', MASTER_LOG_POS=<Exec_Master_Log_Pos>;

START SLAVE;

show slave status;

Fully_initialize

/* on Master =====================
*/

RESET MASTER;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

-- get Master_Log_file
-- get Master_Log_Pos

/* run mysqldump on ssh
mysqldump mydata.sql
*/

UNLOCK TABLES;

/* on Slave =====================
*/

STOP SLAVE;

/* import from ssh
mysql -uroot -p < mydata.sql
*/

RESET SLAVE;

CHANGE MASTER TO MASTER_LOG_FILE='<Master_Log_file>', MASTER_LOG_POS=<Master_Log_Pos>;

START SLAVE;

show slave status;

Ref

댓글

이 블로그의 인기 게시물

Alter table 에서 modify 와 change 의 차이 :: SQL Server

두 개의 차이를 모르는 경우가 많아서 정리합니다.  modify는 필드의 속성값을 바꿀때 사용하구요.. change는 필드명을 바꿀떄 사용합니다.  alter table tbbs modify bNote varchar(2000) NULL; alter table tbbs change bNoteOrg bNoteNew varchar(2000) NULL; change에는 원래 필드와 바꾸고 싶은 필드명을 넣어서 필드명을 바꾸는 것이죠~ 더 많은 SQL Server 팁을 보려면  https://github.com/LowyShin/KnowledgeBase/tree/master/wiki/SQL-Server giip :: Control all Robots and Devices! Free inter-RPA orchestration tool! https://giipasp.azurewebsites.net/

[Classic ASP] Cookie가 삭제 안되는 문제

만든 쿠키가 삭제가 계속 안되서 여기저기 삽질을 했다. 모든 쿠키를 삭제하는 함수도 만들었다. Function CookieClear(cldomain) For Each cookie in Request.Cookies Response.Cookies(cookie).Domain = "." & cldomain Response.Cookies(cookie).Path = "/" Response.Cookies(cookie).Expires = DateAdd("d",-1,now()) Next End Function 그런데.. 안되서 계속 삽질하다가 하나 알았다.  littleworld.net littleworld.co.kr www.littleworld.net  의 모든 값을 지우려고 했으나.. 처음 만든 쿠키가 www.littleworld.net 인 관계로.. 처음에 www.littleworld.net 의 쿠키를 삭제 해야만 나머지가 지워졌다.. -ㅅ-;; 간단하지만 몰랐던 초보적인 사실.. ---- 누구나 쉽게 광고를! http://www.cashtalk.co.kr Free Infrastructure automation & management tool Global Infrastructure Integration Platform http://giip.littleworld.net Subscribe and publish your links as a book with friends  My Favorite Link Share http://link.littleworld.net

BI의 궁극판! Apache Drill을 써보자!

사실 Apache Drill 은 BI(Business Intelligence)라고 부르는 것 보다는 단순 데이터 연결 엔진이다. https://drill.apache.org/ 하지만 내가 왜 극찬을 하느냐면.. DBA로서 항상 문제가 되어왔던게, 이기종 데이터의 변환이나 처리였다. 포맷을 맞추는데 엄청난 시간이 걸리고, 데이터 임포트 실패가 무수하게 나고.. 한 번 잘못 데이터를 추출하면 다시 조정, 변환, 추출하는데 시간이 많이 걸린다. 그런데! Apache Drill은 그냥 RDB를 CSV랑 연결해서 조인해서 통계를 낼 수 있다. 그것도 표준 SQL을 사용하여! 예를 들어, CSV의 세 번째 컬럼이 price 이고, 물건의 판매이력을 PG사에서 CSV로 출력 받았다. 우리 DB와의 검증을 위해서는 수동으로 Import를 한 뒤에 포맷이 안맞아 잘리는 데이터가 있다면 다시 맞춰주고, 재 임포트를 수십 번, 그리고 나서 겨우 들어간 데이터를 조인하여 빠진 데이터를 분간한다. 숫자가 적다면 개발자가 개발로 처리할 수도 있지만, 건수가 하루에 300만건 짜리라면.. 한 달 온 파일은 9천만 건이다. 프로그램으로 고작 처리하는 것이 초당 500건. 거의 20만초, 에러 없이 약 56시간.. 에러가 생기면 다시 56시간.. ㅠㅡㅠ 이런게 현실이기 때문에 쿼리 말고는 방법이 없다. apache drill 의 진면목을 보자! 이번에는 좀 범용 적인 MySQL DB와 붙여 보자. . 난 이번에는 Mac에서 작업을 했기 때문에 그냥 다운 받아서 풀었음.. https://drill.apache.org/download/ 여기서 자기 OS에 맞는 버전을 받아서 설치하시길.. 압축을 풀고 나면 MySQL 커넥터를 붙여야 한다. https://dev.mysql.com/downloads/connector/j/5.1.html 여기서 다운로드 이런 커넥터 들을 붙일 때마다 콘피그를 수정해 줘야 하지만, 몇 번만