MySQL Master Master Replication

As described in the previous post about MySQL Master Slave Replication. This is how to setting up MySQL Master Master Replication.

Master address 192.168.10.1
Slave address 192.168.10.2

Setup Slave

* Edit mysql configuration file on /etc/my.cnf

root@slave:~#nano /etc/my.cnf
log-bin=mysql-bin
binlog-ignore-db="mysql"

* Create a Replication Slave privileges on the Slave for the original Master server:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.47-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT REPLICATION SLAVE ON *.* TO replication@"192.168.10.1" IDENTIFIED BY 'password123#';
mysql> flush privileges;
mysql> exit
Bye

* Restart Slave MySQL service

root@slave:~# killall -9 mysqld mysqld_safe
root@slave:~# /usr/local/mysql/bin/mysqld_safe --user=mysql &

* Get the binary position of the data

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000005 |      106 |              | mysql            |
+------------------+----------+--------------+------------------+
1 row in set (0.01 sec)

Note the File row and Position row for use on the original Master server.

Setup Master

root@master:~# nano /etc/my.cnf
master-host = 192.168.10.2 ##this is the IP of Slave Server##
master-user = replication
master-password = password123#
master-port = 3306

* Restart Master MySQL service

root@master:~# killall -9 mysqld mysqld_safe
root@master:~# /usr/local/mysql/bin/mysqld_safe --user=mysql &

* Login to MySQL and config the Master File settings

mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=106;
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 208.99.198.183
                  Master_User: replicator
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000005
          Read_Master_Log_Pos: 106
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 251
        Relay_Master_Log_File: mysql-bin.000005
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 106
              Relay_Log_Space: 407
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
1 row in set (0.00 sec)

Slave_IO_State status information should identify “Waiting for master to send event”. If it stops at “Connecting to Master” check your log file. By default it is located in /var/log/mysqld.log but may be different on your system. Check your my.cnf file for the exact location of your log file.

Category: Linux | Tags: Comment »


Leave a Reply



Back to top