【问题标题】:MySQL replication fails when it replicate from a slave database serverMySQL 从从数据库服务器复制时复制失败
【发布时间】:2018-05-23 22:49:34
【问题描述】:

我有一个带有 bin 日志文件 bin.000008 的主 MySQL 服务器 A。还有一个从属服务器 B 及其 bin 日志文件 bin.000012。

从 A 到 B 的复制效果很好。

每次我将数据更改到服务器 A 时,服务器 B 都会正确复制它。

有一个新的 MySQL 服务器 C。我使它成为服务器 B 的从属。

问题是:

当我修改服务器 A 上的数据时,服务器 B 会正确复制它。但是服务器 C 没有改变。这意味着从服务器 B 到服务器 C 的复制无效。

我试图在服务器 C 上重新启动从服务器。它说 从二进制日志中读取数据时从主服务器收到致命错误 1236:“从服务器正在使用 CHANGE MASTER TO MASTER_AUTO_POSITION = 1 进行连接,但是master 已经清除了包含 slave 需要的 GTID 的二进制日志。'

这里是每个服务器的主从状态:

服务器 C(服务器 B 的从属服务器):

db> show slave status\G;
|[
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: luexu.com
                  Master_User: Aario
                  Master_Port: 1579
                Connect_Retry: 60
              Master_Log_File: bin.000012
          Read_Master_Log_Pos: 194
               Relay_Log_File: cf3613332a61-relay-bin.000004
                Relay_Log_Pos: 355
        Relay_Master_Log_File: bin.000012
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql,information_schema,performance_schema,sys
           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: 194
              Relay_Log_Space: 569
              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: 65535
                  Master_UUID: dd7aa123-ca18-11e7-9411-0242ac110005
             Master_Info_File: /master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:1-79,
dd7aa123-ca18-11e7-9411-0242ac110005:1-13
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)
]|

服务器 B(服务器 A 的从属服务器,服务器 C 的主服务器):

db> show variables like '%slave%';
+------------------------------+-----------------------+
| Variable_name                | Value                 |
+------------------------------+-----------------------+
| init_slave                   |                       |
| log_slave_updates            | ON                    |
| log_slow_slave_statements    | OFF                   |
| pseudo_slave_mode            | OFF                   |
| rpl_stop_slave_timeout       | 31536000              |
| slave_allow_batching         | OFF                   |
| slave_checkpoint_group       | 512                   |
| slave_checkpoint_period      | 300                   |
| slave_compressed_protocol    | OFF                   |
| slave_exec_mode              | STRICT                |
| slave_load_tmpdir            | /tmp                  |
| slave_max_allowed_packet     | 1073741824            |
| slave_net_timeout            | 60                    |
| slave_parallel_type          | DATABASE              |
| slave_parallel_workers       | 0                     |
| slave_pending_jobs_size_max  | 16777216              |
| slave_preserve_commit_order  | OFF                   |
| slave_rows_search_algorithms | TABLE_SCAN,INDEX_SCAN |
| slave_skip_errors            | OFF                   |
| slave_sql_verify_checksum    | ON                    |
| slave_transaction_retries    | 10                    |
| slave_type_conversions       |                       |
| sql_slave_skip_counter       | 0                     |
+------------------------------+-----------------------+


db> show master status\G;
|[
*************************** 1. row ***************************
File: bin.000012
Position: 194
Binlog_Do_DB:
Binlog_Ignore_DB: mysql,sys,information_schema,performance_schema
Executed_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:1-81,
dd7aa123-ca18-11e7-9411-0242ac110005:1-13
1 row in set (0.00 sec)
]|

db> show slave status\G;
|[
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: luexu.com
                  Master_User: Aario
                  Master_Port: 5961
                Connect_Retry: 60
              Master_Log_File: bin.000008
          Read_Master_Log_Pos: 27885
               Relay_Log_File: 217fcc5843c2-relay-bin.000005
                Relay_Log_Pos: 27684
        Relay_Master_Log_File: bin.000008
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql,sys,information_schema,performance_schema
           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: 27885
              Relay_Log_Space: 27938
              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
                  Master_UUID: c389aee6-ca16-11e7-81e3-0242ac110004
             Master_Info_File: /master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:48-81
            Executed_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:1-81,
dd7aa123-ca18-11e7-9411-0242ac110005:1-13
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)
]|

服务器 A(服务器 B 的主服务器):

db> show master status\G;
|[
*************************** 1. row ***************************
File: bin.000008
Position: 27885
Binlog_Do_DB:
Binlog_Ignore_DB: mysql,sys,information_schema,performance_schema
Executed_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:1-81
1 row in set (0.00 sec)
]|

重启服务器 C 上的从站:

db> stop slave;
db> start slave;
db> show slave status\G;
|[
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: luexu.com
                  Master_User: Aario
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: cf3613332a61-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql,information_schema,performance_schema,sys
           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: 0
              Relay_Log_Space: 308
              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: 1236
                Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.'
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 65535
                  Master_UUID: dd7aa123-ca18-11e7-9411-0242ac110005
             Master_Info_File: /master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 171210 04:01:51
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: 074c1f93-dd08-11e7-b173-0242ac110004:1-3
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
]|

【问题讨论】:

    标签: mysql


    【解决方案1】:

    我不确定您的问题,因此只是一些想法 - 也许您会从中找到一些灵感:

    设置链复制 A->B->C 是否有一些非常重要的原因?如果不能避免这种复杂性,只需制作 A 的 C 副本(您可以通过简单克隆已经工作的 B 副本来实现 - 请参见此处:http://mysql.freeideas.cz/subdom/mysql/2017/08/14/create-new-replica-by-copying-data-and-log-files-on-os-level/

    如果您确实必须链接您的复制,那么它通常可以正常工作,我们使用它来对架构进行更大的更改而无需停机很长时间,它甚至可以在不同的 MySQL 版本之间工作。

    当我们需要从一个云提供商转移到另一个云提供商时,我们第一次使用它 - 我们使用 (A) 旧云上的旧主服务器 -> (B) 新云上的新预期主服务器 -> (C) 上的副本应用程序的新云。目前我们将其设置为使用新版本的 MySQL 进行新应用开发 - (A) old 5.5 Master -> (B) 5.7 replica/master -> (C) 5.7 replicas for app。

    您只需在“主副本”上设置“log_slave_updates=ON”,并以与从 A 创建 B 相同的方式从 B 创建 C 副本 - 请参阅此处的一般说明:http://mysql.freeideas.cz/subdom/mysql/2016/11/10/how-to-manually-set-mysql-replication/

    意思——你必须在你的 B 上为 C 进行转储,复制停止并且表被锁定以防止更改,并记下 B 的主状态并使用它来设置 C。当然——你必须确保 B 上的 bin 日志能够存活“足够长” - 将 B 上的“expire_logs_days”设置为几天(当然你必须有足够的磁盘空间)。所有这些设置更改都需要重新启动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      • 1970-01-01
      相关资源
      最近更新 更多