Monday 17 October 2011

MySQL replication set up

there are some basic steps to set mysql replication.

wee start from MASTER

1.see that binary logs are enabled.and also set server id in my.cnf file
If not then do as:

log-bin=mysql-bin ##THIS SHOULD BE THE SAME AS HERE
server-id=1
Restart the server


2.in the mysql shell issue a command
mysql > show binary logs;

If the binary logs are enabled it should not return the empty result set.If return empty set you are wrong somewhere pls check that step 1 is completed...??
otherwise you will face problem in replication

If done come to step 3.

3.In mysql shell write
mysql > FLUSH TABLES WITH READ LOCK;

Now just generate the dump of your master as or any other method u want

mysqldump -uroot -proot --all-databases --master-data > dbdump.db

4. mysql > show master status;
note down the binary log and position.


5.now In mysql shell
mysql > UNLOCK TABLES;


6.mysql > CREATE USER 'repl'@ '%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@ '%' IDENTIFIED BY 'password';


NOW ON THE SLAVE DO SOME WORK

1.IN my.cnf
server-id=2
#and also try to write relay-log

restart the mysql server

2.
mysql > stop slave;

mysql > CHANGE MASTER TO
MASTER_HOST=’X.X.X.X’,
MASTER_USER=’user’,
MASTER_PASSWORD=’password’,
MASTER_PORT=3306,
MASTER_LOG_FILE=’mysql-bin.000001?,
MASTER_LOG_POS=98,
MASTER_CONNECT_RETRY=10;


mysql > start slave ;


mysql > show slave status\G

Now It should be working fine





No comments:

Post a Comment