Last_Errno: 1594 the master's binary log is corrupted Last_SQL_Errno: 1062

mysql主从复制不同步异常

查看从库同步状态,发现Slave_SQL_Running: No状态异常,主备库已经不再同步,初步怀疑是断电倒是binlog的问题
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.3
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: log-bin.000030
          Read_Master_Log_Pos: 54007656
               Relay_Log_File: slave01-relay-bin.000068
                Relay_Log_Pos: 63524817
        Relay_Master_Log_File: log-bin.000029
       ..........................................
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 1594
                   Last_Error: Relay log read failure: Could not parse relay log event entry.
          The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), 
          the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log),
          a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log 
          or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.
          

 查看下slave的error log 发现binlog最后截止在 'log-bin.000029' position 63524608

2017-10-13T05:44:56.382911Z 1 [Note] Slave I/O thread killed while reading event for channel ''
2017-10-13T05:44:56.382941Z 1 [Note] Slave I/O thread exiting for channel '', read up to log 'log-bin.000030', position 54007656
2017-10-13T05:44:58.675958Z 7 [Note] Slave I/O thread: Start semi-sync replication to master 'repl@192.168.1.3:3306' in log 'log-bin.000030' at position 54007656
2017-10-13T05:44:58.675993Z 7 [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2017-10-13T05:44:58.677146Z 7 [Note] Slave I/O thread for channel '': connected to master 'repl@192.168.1.3:3306',replication started in log 'log-bin.000030' at position 54007656
2017-10-13T05:44:58.687664Z 8 [Warning] Slave SQL for channel '': If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
2017-10-13T05:44:58.688769Z 8 [Note] Slave SQL thread for channel '' initialized, starting replication in log 'log-bin.000029' at position 63524608, relay log './slave01-relay-bin.000068' position: 63524817
2017-10-13T05:44:58.688858Z 8 [ERROR] Error in Log_event::read_log_event(): 'read error', data_len: 65, event_type: 34
2017-10-13T05:44:58.688865Z 8 [ERROR] Error reading relay log event for channel '': slave SQL thread aborted because of I/O error
2017-10-13T05:44:58.688877Z 8 [ERROR] Slave SQL for channel '': Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), 
the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know
 their names by issuing 'SHOW SLAVE STATUS' on this slave. Error_code: 1594
2017-10-13T05:44:58.688881Z 8 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". 
We stopped at log 'log-bin.000029' position 63524608

mysql>show binlog events in 'log-bin.000029' from 63524608 limit 3; 查看位于 pos 为 63524608 的一行记录下 endpos 63524608

于是采用在slave上重新定位master的binlog的方法以重新同步主备库 

mysql> stop slave;
Query OK, 0 rows affected (0.03 sec)

mysql> change master to master_host='192.168.1.3',master_user='repl',master_password='ppay', master_log_file='log-bin.000029',master_log_pos=63524608;

Query OK, 0 rows affected, 2 warnings (0.16 sec)

开启slave 
mysql> start slave ;
Query OK, 0 rows affected (0.02 sec)

查看同步状态

mysql> show  slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.3
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: log-bin.000030
          Read_Master_Log_Pos: 54416555
               Relay_Log_File: slave01-relay-bin.000002
                Relay_Log_Pos: 318
        Relay_Master_Log_File: log-bin.000029
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
            ...................................
                   Last_Errno: 1062
                   Last_Error: Could not execute Write_rows event on table log.logsver; Duplicate entry '874655' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log log-bin.000029, end_log_pos 63525006
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 63524608
              Relay_Log_Space: 54417775
            ....................................
               Last_SQL_Errno: 1062
               Last_SQL_Error: Could not execute Write_rows event on table log.logsver; Duplicate entry '874655' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log log-bin.000029, end_log_pos 63525006
  Replicate_Ignore_Server_Ids: 
            ....................................
ERROR: 
No query specified


重新启动slave之后,又出现了新的错误,常见的error 1062,主键重复

主键重复

在slave已经有874655该条记录,又在master上插入了同一条记录,所以报错。
Last_SQL_Error: Could not execute Write_rows event on table log.logsver; 
Duplicate entry '874655' for key 'PRIMARY', 
Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; 
the event's master log log-bin.000029, end_log_pos 63525006

解决方法:

在slave上先看下log.logsver表结构,在主备库上查询重复的记录状态

mysql> desc log.logsver;

+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| id       | int(100)     | NO   | PRI | NULL    | auto_increment |
| name     | varchar(50)  | NO   |     | NULL    |                |
| level    | int(2)       | NO   |     | NULL    |                |
| msg      | varchar(255) | NO   |     | NULL    |                |
| intime   | datetime     | NO   |     | NULL    |                |
| codename | varchar(25)  | YES  |     | NULL    |                |
| codefunc | varchar(25)  | YES  |     | NULL    |                |
| codeline | varchar(10)  | YES  |     | NULL    |                |
| process  | varchar(10)  | YES  |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+
停止slave
mysql>stop slave;

删除重复的主键
mysql> delete from logsver where id=874655;
Query OK, 1 row affected (0.07 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

重新开启salve
mysql> start slave;
Query OK, 0 rows affected (0.02 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.3
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: log-bin.000030
          Read_Master_Log_Pos: 54997622
               Relay_Log_File: slave01-relay-bin.000003
                Relay_Log_Pos: 43225
        Relay_Master_Log_File: log-bin.000030
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
.................................
1 row in set (0.00 sec)


在master上和slave上分别确认,

mysql> select count(*) from  logsver where id=874655;
+----------+
| count(*) |
+----------+
|        1 |
+----------+

mysql> select count(*) from  logsver where id=874655;
+----------+
| count(*) |
+----------+
|        1 |
+----------+

至此,主备库重新同步正常

### 回答1: last_io_errno: 1236是指在最后一次输入/输出操作中出现了错误代码1236。 错误代码1236代表数据库服务器连接超时。这意味着数据库服务器在规定的时间内未响应客户端的请求,可能因为网络问题或服务器负载过高。 当客户端与数据库服务器建立连接后,它会发送查询请求或执行其他操作。服务器必须在一定的时间内响应这些请求。如果服务器在规定时间内未能响应请求,就会发生超时错误。 造成连接超时的原因有很多,如网络延迟、服务器资源不足、数据库负载过高等。解决超时错误的方法包括: 1. 检查网络连接和服务器状况:确保网络连接稳定,并检查服务器的负载和可用资源是否充足,确保数据库服务器能够正常运行。 2. 调整连接超时时间:根据实际情况,适当延长连接超时时间,以便服务器有足够的时间来响应请求。这可以在数据库连接参数中进行相关设置。 3. 优化数据库查询:通过优化查询语句、创建索引和适当调整数据库设计等方式,提高数据库的查询性能,减少响应时间。 4. 分散负载:如果数据库服务器负载过高,可以考虑分散负载到多个服务器上,以提高整体性能。 5. 更新数据库和服务器软件版本:确保数据库和服务器软件版本是最新的,因为软件更新通常会修复一些性能和稳定性问题。 总之,last_io_errno: 1236是连接超时错误的错误代码,通过检查网络连接、服务器负载情况和优化数据库查询等措施,可以解决这个问题。 ### 回答2: last_io_errno: 1236 是MySQL数据库的一个错误代码。该错误代码表示与主从复制相关的问题,具体是指主从数据库之间的连接出现错误。 在MySQL主从复制中,主数据库负责处理所有的写操作,并将这些写操作的日志记录发送到从数据库进行执行,以保持主从数据库的数据一致性。当从数据库无法连接到主数据库时,就会出现last_io_errno: 1236 错误。 造成last_io_errno: 1236 错误的原因可能有多种,其中包括网络问题、主数据库宕机或者设置的错误等。 解决这个错误的方法可以包括以下几步: 1. 检查网络连接是否正常,确保主数据库和从数据库之间的通信没有问题。 2. 检查主数据库是否正常运行,确保它没有宕机或者出现其他故障。 3. 检查MySQL主从复制的设置是否正确,包括主数据库的binlog配置和从数据库的replication配置是否正确。 4. 尝试重新启动从数据库,以确保它能够重新连接主数据库并进行同步。 如果上述方法无法解决问题,可能需要进一步排查错误的具体原因并根据具体情况采取不同的解决方法。可以通过查看MySQL的错误日志或者运行相应的诊断命令来获取更多的错误信息,以便进行进一步的故障排除。 ### 回答3: last_io_errno: 1236是指最近一次I/O(输入/输出)操作发生的错误代码是1236。 错误代码1236是MySQL数据库中的一个错误代码,表示一个问题出现在处理复制操作时。具体来说,它指示从服务器无法连接到主服务器来获取或处理复制日志事件。 这个错误可能发生在主从复制设置中,当从服务器无法与主服务器建立连接时。可能的原因包括网络问题、访问权限问题或主服务器宕机等。如果无法建立连接,从服务器将无法获取主服务器上的更新日志,并无法进行数据复制。 为了解决这个问题,可以通过以下几个步骤来进行排查: 1. 确保网络连接正常:检查网络连接是否稳定,并确保从服务器能够与主服务器进行通信。 2. 检查访问权限:确保从服务器具有足够的权限来连接和复制主服务器上的数据。检查相关的用户权限和授权设置。 3. 检查主服务器状态:验证主服务器是否处于运行状态,确保没有出现宕机或其他故障。 4. 检查错误日志:查看MySQL错误日志文件,了解更多关于错误的详细信息。错误日志通常位于MySQL安装目录的日志文件夹中。 5. 重新启动从服务器:有时,重新启动从服务器可以解决临时的连接问题。 如果以上步骤都无法解决问题,可以考虑联系数据库管理员或MySQL技术支持人员,以获取更进一步的帮助和支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值