Could not find first log file name in binary log index file

今天服务器移动机柜,其中192.168.0.144和192.168.0.143是两台主主复制的mysql,
首先关闭keepalived,然后直接关闭了mysql,没有先关闭slave.导致服务器换好位置之后,启动mysql。启动slave,发现两台mysql都报错了,具体如下:
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.0.144
Master_User: info_syncer
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.001831
Read_Master_Log_Pos: 1008873351
Relay_Log_File: mysql-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.001831
Slave_IO_Running: No
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: 1008873351
Relay_Log_Space: 842
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: 2
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec)
ERROR: No query specified
'Could not find first log file name in binary log index file'的解决办法
以下是日志出错问题的解决方案:
一:从机器停止slave
mysql> slave stop;
二:到master机器登陆mysql,记录master的bin的位置,
mysql> show mster status;
+-------------------+----------+--------------+-------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+-------------------------------------------+
| mysqld-bin.000010 | 106 | | information_schema,mysql |
+-------------------+----------+--------------+-------------------------------------------+
日志为mysqld-bin.000010
三:在主库刷新日志:
mysql> flush logs;
因为刷新日志file的位置会+1,即File变成为:mysqld-bin.000011,同时
马上到slave执行
四:mysql>slave stop;
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysqld-bin.000011',MASTER_LOG_POS=106;
mysql> slave start;
mysql> show slave status\G;
问题解决。。。。
然后flush logs 到底做了什么?
首先介绍下:MySQL 有几个不同的日志文件,可以帮助你找出mysqld 内部发生的事情:
日志文件:记入文件中的信息类型,事务日志
错误日志:记录启动、运行或停止mysqld 时出 现的问题。
查询日志:记录建立的客户端连接和执行的语句。
更新日志:记录更改数据的语句。不赞成使用该日志。
二进制日志:记录所有更改数据的语句。还用于复制。
慢日志:记录所有执行时间超过long_query_time 秒的所有查询或不使用索引的查询。
flush logs 用于关闭并重新打开所有的日志文件。如果您已经指定了一个更新日志文件或一个二进制日志文件,则相对于前一个文件,日志文件的扩展号增加1,对于错误日志和事务日志,flush logs 会让MySQL关闭并重新打开日志文件。
小结:出现这个错误原因是,由于还没有stop slave ,就关闭主的mysql,导致mysql-relay-bin.index出现问题,找不到需要的binlog 文件,这样的话,你只要flsush logs,让主的binlog扩展号加1,这样mysql-relay-bin.index就能记录上这个新的binlog文件,然后从库从新change到主的这个binlog文件,就可以了。
请使用浏览器的分享功能分享到微信等