Solved

Two-way MySQL replication not working?

Posted on 2014-03-20
2
306 Views
Last Modified: 2015-02-09
I have used this tutorial to setup two way replication:
http://www.neocodesoftware.com/replication/

The problem is, if I shut down server 1, then make a change on server 2, and then restart server 1, the changes on 2 do not replicate to 1.

however, If I shut down server 2, and make a change to server 1, then restart server 2, the changes made on server 1 are propogated to server 2.

So it is working but only server 1->server 2, and not the other way around.

Here are the configs (below). How do I troubleshoot this?
my.cnf at Master1

server-id        = 1
auto-increment-increment = 10
auto-increment-offset = 1
replicate-same-server-id = 0
log-bin          = /var/lib/mysql/mysql-bin
relay-log        = /var/lib/mysql/mysql-relay
relay-log-index  = /var/lib/mysql/mysql-relay.index
expire_logs_days = 10
max_binlog_size  = 100M
binlog_format    = 'MIXED'

my.cnf at Master2

server-id               = 2
replicate-same-server-id = 0
auto-increment-increment = 10
auto-increment-offset = 2
#expire_logs_days       = 10
#max_binlog_size         = 100M
log-bin          = /var/log/mysql/mysql-bin
#relay-log        = /var/log/mysql/mysql-relay-bin
#relay-log-index  = /var/log/mysql/mysql-relay.index
expire_logs_days = 10
max_binlog_size  = 100M
binlog_format    = 'MIXED'



mysql> stop slave;
mysql> CHANGE MASTER TO MASTER_HOST='192.30.164.115', MASTER_USER='repl', MASTER_PASSWORD='60NmzdnsLBUBLnu44MSq';
mysql> start slave;




mysql>  SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.30.164.115
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000030
          Read_Master_Log_Pos: 1027
               Relay_Log_File: mysqld-relay-bin.000020
                Relay_Log_Pos: 1173
        Relay_Master_Log_File: mysql-bin.000030
             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: 1027
              Relay_Log_Space: 1476
              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:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
1 row in set (0.00 sec)



mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000030 |      207 |              |                  |
+------------------+----------+--------------+------------------+

Open in new window

0
Comment
Question by:DrDamnit
  • 2
2 Comments
 
LVL 77

Expert Comment

by:arnold
ID: 39944875
Look at show slave status on both systems for any replication errors.

Show slave status you posted, is that from server 1 or from server 2?
Make sure that the master_server_id reflects the other sserver id:slave on 1 should reflect 2 as the master. Slave on 2 should reflect 1.

Why are you changing master?


You are missing the replicate-db directives and binlogemail-do-DB. This is that you only replicate specific database excluding the mysql database.
0
 
LVL 77

Accepted Solution

by:
arnold earned 500 total points
ID: 39944894
You should name your binlog such that includes the server name,  this way when you show slave status reflects the log file with the incorrect name(same name as the slave) you'll more easily determine that you misreferenced the master on one of them.

You should also include the reference to the master host in the my.cnf such that as soon as the system comes up, it will reestablish the connection automatically

Look at the master IP.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question