错误 1236 -“在二进制日志索引文件中找不到第一个日志文件名”

rin*_*ogo 12 mysql replication mariadb

我们的设置:

  • 大师:MariaDB 10.0.21
  • 从站:MariaDB 10.0.17

复制工作正常,直到最近必须从转储中恢复从属数据库。我执行了所有必要的步骤:转储主数据库,将转储传输到从数据库,删除旧数据库,执行转储以恢复数据库,执行适当的CHANGE MASTER命令,最后START SLAVE.

我收到错误: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

从站需要从主站获取的第一个日志文件是mysql-bin.000289. 我可以看到这是存在于主人身上的: 在此处输入图片说明

我还可以看到 master 上的二进制日志索引似乎有这个日志文件的条目: 在此处输入图片说明

仍然复制不起作用 - 我不断收到同样的错误。我没有想法 - 接下来我应该检查什么?


更新:SHOW SLAVE STATUS\G按要求输出:

MariaDB [(none)]> SHOW SLAVE STATUS\G
--------------
SHOW SLAVE STATUS
--------------

*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 127.0.0.1
                  Master_User: replication
                  Master_Port: 1234
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000289
          Read_Master_Log_Pos: 342
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000289
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              Replicate_Do_DB: xxx_yyy,xxx_zzz
          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: 342
              Relay_Log_Space: 248
              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: NULL
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: 'Could not find first log file name in binary log index file'
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 3
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos: 
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

额外要求的信息:

root@master [818 18:54:22 /var/lib/mysql]# ls -l /var/lib/mysql/mysql-bin.000289
-rw-rw---- 1 mysql mysql 1074010194 May 19 03:28 /var/lib/mysql/mysql-bin.000289
root@master [819 18:54:29 /var/lib/mysql]# ls mysql-bin.00029*
mysql-bin.000290  mysql-bin.000291  mysql-bin.000292 #(Yes, it was created)
root@master [821 18:56:52 /var/lib/mysql]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6345382
Server version: 10.0.21-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> SHOW BINARY LOGS;
+------------------+------------+
| Log_name         | File_size  |
+------------------+------------+
| mysql-bin.000279 | 1074114047 |
| mysql-bin.000280 | 1074004090 |
| mysql-bin.000281 | 1074035416 |
| mysql-bin.000282 | 1073895128 |
| mysql-bin.000283 | 1073742000 |
| mysql-bin.000284 | 1074219591 |
| mysql-bin.000285 | 1074184547 |
| mysql-bin.000286 | 1074217812 |
| mysql-bin.000287 | 1022733058 |
| mysql-bin.000288 |     265069 |
| mysql-bin.000289 | 1074010194 |
| mysql-bin.000290 | 1074200346 |
| mysql-bin.000291 |  617421886 |
| mysql-bin.000292 |     265028 |
+------------------+------------+
14 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye
root@master [821 18:57:24 /var/lib/mysql]# mysqlbinlog mysql-bin.000289 > /tmp/somefile.txt
root@master [822 18:58:13 /var/lib/mysql]# tail /tmp/somefile.txt 
# at 1074010124
#160519  3:28:59 server id 5  end_log_pos 1074010151    Xid = 417608063
COMMIT/*!*/;
# at 1074010151
#160519  3:28:59 server id 5  end_log_pos 1074010194    Rotate to mysql-bin.000290  pos: 4
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
root@master [823 18:58:31 /var/lib/mysql]# 
Run Code Online (Sandbox Code Playgroud)

/etc/my.cnf.d/server.cnf (摘抄):

# BINARY LOGGING #
log-bin                        = /var/lib/mysql/mysql-bin
expire-logs-days               = 14
sync-binlog                    = 1
Run Code Online (Sandbox Code Playgroud)

编辑:职位 342 似乎确实存在:

root@master [826 12:15:33 /var/lib/mysql]# grep "end_log_pos 342 " /tmp/somefile.txt
#160517 14:43:13 server id 5  end_log_pos 342   Binlog checkpoint mysql-bin.000288
Run Code Online (Sandbox Code Playgroud)

And*_*ley 10

如果一切都失败了,您可能会发现需要重置从属并重新启动复制。从https://www.redips.net/mysql/replication-slave-relay-log-corrupted/

# First note current settings (note Relay_Master_Log_File and Exec_Master_Log_Pos)
mysql> show slave status\G
# then stop slave
mysql> stop slave;
# make slave forget its replication position in the master's binary log
mysql> reset slave;
# change slave to start reading from stopped position
mysql> change master to master_log_file='mysql-bin.XXX', master_log_pos=XXX;
# start slave
mysql> start slave;
Run Code Online (Sandbox Code Playgroud)

  • @yper-trollᵀᴹ - 是的,但是 Stackexchange 的一半是用于问题的存档,这些问题不可避免地会出现在 Google 搜索的顶部,以寻找其他有相同问题的人。我自己也遇到了完全相同的问题,这就是我的解决方案(尤其是当我真的花了几个小时试图解决它时,因为大多数其他页面只显示相同的其他答案)。另一个“错误”答案有 2 个赞成票的事实证明了这一点。 (4认同)

小智 6

你似乎没有连接到你认为的主人。根据您在主站上的二进制日志,您似乎拥有:

#160519 3:28:59服务器 ID 5

但是根据 SHOW SLAVE STATUS 我们看到:

         Master_Server_Id: 3
Run Code Online (Sandbox Code Playgroud)

此外,您似乎是在本地主机上连接,但您暗示您的主/从在不同的主机上:

              Master_Host: 127.0.0.1
Run Code Online (Sandbox Code Playgroud)


Rol*_*DBA 5

错误消息就是答案。

查看SHOW BINARY LOGS查询的输出:

+------------------+------------+
| Log_name         | File_size  |
+------------------+------------+
| mysql-bin.000279 | 1074114047 |
| mysql-bin.000280 | 1074004090 |
| mysql-bin.000281 | 1074035416 |
| mysql-bin.000282 | 1073895128 |
Run Code Online (Sandbox Code Playgroud)

显示中没有mysql-bin.000278。

除非二进制日志轮换,否则 mysql-bin.index 的内容是错误的。

请将 的内容mysql-bin.index与现有的 binlogs 文件进行比较并确保它们匹配。你可以在 Master 上解决这个问题

mysql> PURGE BINARY LOGS TO 'mysql-bin.000279';
Run Code Online (Sandbox Code Playgroud)

然后去 Slave 并运行

mysql> STOP SLAVE; START SLAVE;
Run Code Online (Sandbox Code Playgroud)

试一试 !!!


Ano*_*arZ 5

更新:此答案涵盖了一般错误分类。有关如何最好地处理 OP 的确切查询的更具体答案,请参阅此问题的其他答案

最关键的复制错误之一Got fatal error 1236 可以由多种原因触发,其中之一就是这个问题的标题。

从二进制日志读取数据时,从主服务器收到致命错误 1236:“在二进制日志索引文件中找不到第一个日志文件名”

当从服务器需要用于复制的二进制日志在主数据库服务器上不再存在时,就会发生此错误。

很多场景都会导致这种情况:

  • 主服务器通过系统变量过期二进制日志expire_logs_days(my.cnf,如果您设置expire_logs_days旧的二进制日志 自动过期并被删除;当 MySQL 打开一个新的二进制日志文件时,它会检查旧的二进制日志,并清除任何比 expire_logs_days 值旧的二进制日志)
  • 有人通过PURGE BINARY LOGS命令或通过rm -f命令从 master 手动删除了二进制日志
  • 您有一些cronjob存档较旧的二进制日志以声明磁盘空间

为了解决这个问题,我能想到的唯一干净的解决方案是从主服务器备份或复制拓扑中的其他从服务器重新创建从服务器。

参考:mysql复制出现致命错误