Pages

Wednesday, June 22, 2011

MYSQL-REPLICATION

MYSQL-REPLICATION
Binary login must be enabled on master server prior to replication.
2 process will execute on the each slave server to handle replication.
1 process execute on master server per-slave server
Replication is Asynchronous which means that changes are committed to one node and then it is
propagated to N number of slaves.
Ideal for non-updating application.
REPLICATION CONFIGURATION
Master Server: 192.168.1.100
Slave Server: 192.168.1.31
Slave username: replica
Slave Password: redhat
Put the following in your master my.cnf file under [mysqld] section:
# changes made to do master
server-id = 1
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
datadir = /var/lib/mysql/
log-bin = /var/lib/mysql/mysql-bin
# end master
Copy the following to slave’s my.cnf under [mysqld] section:
# changes made to do slave
server-id = 2
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
datadir = /var/lib/mysql/
# end slave setup
Create user on master:
mysql > grant replication slave on *.* to replica@'192.168.1.100'
identified by 'redhat';
Do a dump of data to move to slave:
mysqldump -u root --all-databases --single-transaction --master-
data=1 > masterdump.sql
import dump on slave:
mysql < masterdump.sql After dump is imported go in to mysql client by typing mysql. Let us tell the slave which master to connect to and what login/password to use: mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.100',
MASTER_USER='replica', MASTER_PASSWORD='redhat';
Let us start the slave:
mysql> start slave;
You can check the status of the slave by typing:
mysql> show slave status;

No comments:

Post a Comment