Configuring MySQL replication on two nodes

Yestrerday im configured MySQL replica on two Linux nodes (CentOS).

Follow me to configure this on your servers. But for very safe dump the databases you will need to stop both MySQL servers on master and slave nodes.

1) Stop MySQL master, and go to /etc/my.cnf (or what config you are use for starting mysql). Edit this:

[mysqld]
server-id = 1
log-bin = /var/lib/mysql/mysql-bin #if its your data directory

2) Then you should copy your data diricetory /var/lib/mysql to slave mysql data directory

3) Start mysqld on master server and go to mysql master shell, then type there:
GRANT replication slave ON *.* TO "repluser"@"ip_of_slave_server" IDENTIFIED BY "replpassword";
Now your master server is ready, go to slave server

4) Change or add this to slave my.cnf config

[mysqld]
server-id = 2

4) Start mysqld on slave server and go to mysql slave shell, then type there:

CHANGE MASTER TO MASTER_HOST = "ip_of_master_server", MASTER_USER = "repluser", MASTER_PASSWORD = "replpassword";
START SLAVE;
SHOW SLAVE STATUS\G

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.