Mysql Replication set up
MySQL Failover Circular Replication
Assume we have 2 servers: Server1 and Server2.
Server1 Settings
- Put the option file my.cnf to Server1 path /etc with these settings:
log-bin=mysql-bin server-id = 1 auto_increment_increment = 10 auto_increment_offset = 1
-
Change mode/permission for my.cnf to rw_r__r_ else mysql will igonore it. sudo chmod 644 my.cnf
-
Stop and start mysql. cd /Library/StartupItems/MySQLCOM sudo ./MySQLCOM stop sudo ./MySQLCOM start
-
Configure the server:
create a user for replication process:
cd /usr/local/mysql/bin ./mysql -p -u root
create user replicant@'%' identified by 'password';
Grant access rights:
GRANT SELECT, PROCESS, FILE, SUPER, REPLICATION CLIENT, REPLICATION SLAVE, RELOAD ON . TO replicant@'%'; Flush Privileges;
Specify the info for the serve2:
CHANGE MASTER TO MASTER_HOST='ip_of_server2', MASTER_USER='replication_user_name_on_server2', MASTER_PASSWORD='replication_password_on_server2';
Start the listerner:
Start slave;
Verify whether the replication is working:
show slave status\G
Server2 Settings
- Put the option file my.cnf on to Server2 path /etc with these settings:
log-bin=mysql-bin server-id = 2 auto_increment_increment = 10 auto_increment_offset = 2
-
Change mode/permission for my.cnf to rw_r__r_ else mysql will igonore it. sudo chmod 644 my.cnf
-
Stop and start mysql. cd /Library/StartupItems/MySQLCOM sudo ./MySQLCOM stop sudo ./MySQLCOM start
-
Configure the server:
create a user for replication process:
cd /usr/local/mysql/bin ./mysql -p -u root
create user replicant@'%' identified by 'password';
Grant access rights:
GRANT SELECT, PROCESS, FILE, SUPER, REPLICATION CLIENT, REPLICATION SLAVE, RELOAD ON . TO replicant@'%'; Flush Privileges;
Specify the info for the serve1:
CHANGE MASTER TO MASTER_HOST='ip_of_server1', MASTER_USER='replication_user_name_on_server1', MASTER_PASSWORD='replication_password_on_server1';
Example:
CHANGE MASTER TO MASTER_HOST='125.564.12.1',
MASTER_USER='replicant', MASTER_PASSWORD='password';
Load data from Server1:
Load Data from Master;
Start the listerner:
Start slave;