简体   繁体   English

MySQL从复制失败

[英]mysql slave replication failed

I have a situation where dns server get the records for its master and all the records are being replicated from master to slave and slave is being used for the resolution. 我有一种情况,DNS服务器会获取其主服务器的记录,并且所有记录都将从主服务器复制到从属服务器,而从属服务器则用于解析。 The replication broke after the mysql server upgrade. mysql服务器升级后,复制中断。 The mysql server stopped and name of the log file and log position changed until mysql was recovered. mysql服务器停止,日志文件名和日志位置更改,直到恢复mysql。 Now i know if i change the log position and log file name, the replication will start but i will miss a lot of updates and that i don't want. 现在,我知道如果我更改日志位置和日志文件名,复制将开始,但我会错过很多更新,而我不希望这样做。 What should i do to restart the master slave replication without losing any updates on the master. 我应该怎么做才能重新启动主从复制而又不丢失任何主更新。 Every single update is important. 每个更新都很重要。 Here are some information from slave status. 以下是有关从站状态的一些信息。

 Slave_IO_Running: No
 Slave_SQL_Running: Yes

Last_IO_Errno: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

Thanks 谢谢

You may be in for a nice surprise but here is goes: 您可能会感到很惊喜,但是这里是这样:

Run SHOW SLAVE STATUS\\G . 运行SHOW SLAVE STATUS\\G For the sake of example, let's say you get this: 举个例子,假设您得到以下信息:

             Slave_IO_State: Waiting for master to send event
                Master_Host: 10.64.68.253
                Master_User: replusername
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: mysql-bin.003202
        Read_Master_Log_Pos: 577991837
             Relay_Log_File: relay-bin.010449
              Relay_Log_Pos: 306229695
      Relay_Master_Log_File: mysql-bin.003202
           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: 577991837
            Relay_Log_Space: 306229695
            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

You choose the following from the display: 您从显示中选择以下内容:

  • Relay_Master_Log_File ( mysql-bin.003202 ) Relay_Master_Log_Filemysql-bin.003202
  • Exec_Master_Log_Pos ( 577991837 ) Exec_Master_Log_Pos577991837

Here is why: Relay_Master_Log_File and Exec_Master_Log_Pos represent binlog entry from the Master that made it to the Slave and was executed successfully. 原因如下: Relay_Master_Log_FileExec_Master_Log_Pos表示来自Master的binlog条目,该条目将其发送到Slave并成功执行。 Simply pickup from there. 只需从那里取货。

You would simply run this code: Exec_Master_Log_Pos 您只需运行以下代码: Exec_Master_Log_Pos

STOP SLAVE;
CHANGE MASTER TO
MASTER_LOG_FILE='mysql-bin.003202',
MASTER_LOG_POS=577991837;
START SLAVE;

Give it a Try !!! 试试看 !!!

CAVEAT 警告

If Relay_Master_Log_File no longer exists on the Master, you may have to do some damage control. 如果Relay_Master_Log_File不再存在Relay_Master_Log_File ,则可能必须进行一些损坏控制。 Given the SHOW SLAVE STATUS\\G mentioned before, you may have to skip to the next binary log on the Master as follows: 鉴于前面提到的SHOW SLAVE STATUS\\G ,您可能必须跳到主服务器上的下一个二进制日志,如下所示:

STOP SLAVE;
CHANGE MASTER TO
MASTER_LOG_FILE='mysql-bin.003203',
MASTER_LOG_POS=4;
START SLAVE;

If replication catches up, you are not out of the woods just. 如果复制赶上了潮流,那么您就不会走出困境。 You may have to download Percona Toolkit and run pt-table-checksum and pt-table-sync to repair the lost data on the Slave. 您可能必须下载Percona Toolkit并运行pt-table-checksumpt-table-sync才能修复从站上丢失的数据。

If replication does not get off the ground, you will have to perform due diligence and reload the Slave. 如果复制没有成功,您将必须执行尽职调查并重新加载从站。

Hopefully, you may not have to do anything in this caveat if replication works with the original suggestion. 希望如果复制符合原始建议,您可能不必在此警告中做任何事情。

The given answer didn't work for me. 给定的答案对我不起作用。 Actually, the proper file that should be taken and set as a master_log_file should be copied from another place. 实际上,应该从另一个位置复制应采用并设置为master_log_file的适当文件。 Giving you the instructions that worked for me: 向您提供对我有用的说明:

Slave Server: stop slave;


In Master Server: flush logs


In Master Server: show master status; — take note of the master log file and master log position (on my end is 'peer-bin.000264' and pos=120)

Slave Server : CHANGE MASTER TO MASTER_LOG_FILE=’peer-bin.000264′, MASTER_LOG_POS=120;


Slave Server: start slave;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM