zoukankan      html  css  js  c++  java
  • MySQL主主互备不同步的解决方法

    MySQL主主互备不同步

    首先在服务器上执行show slave satus;可以看到很多同步的参数: 

    Master_Log_File: SLAVE中的I/O线程当前正在读取的主服务器二进制日志文件的名称
    Read_Master_Log_Pos: 在当前的主服务器二进制日志中,SLAVE中的I/O线程已经读取的位置
    Relay_Log_File: SQL线程当前正在读取和执行的中继日志文件的名称
    Relay_Log_Pos: 在当前的中继日志中,SQL线程已读取和执行的位置
    Relay_Master_Log_File: 由SQL线程执行的包含多数近期事件的主服务器二进制日志文件的名称
    Slave_IO_Running: I/O线程是否被启动并成功地连接到主服务器上
    Slave_SQL_Running: SQL线程是否被启动
    Seconds_Behind_Master: 从属服务器SQL线程和从属服务器I/O线程之间的时间差距,单位以秒计

    同步的整个过程反映到从服务器上,对应三套日志信息,可在从服务器上用如下命令查看:

    mysql> SHOW SLAVE STATUS;

    Master_Log_File & Read_Master_Log_Pos:下一个传输的主日志信息。

    Relay_Master_Log_File & Exec_Master_Log_Pos:下一个执行的主日志信息。

    Relay_Log_File & Relay_Log_Pos:下一个执行的中继日志信息。

    Mysql复制Relay log read failure 的问题

    Mysql主从复制模式中,slave上报错 “relay log read failure”,导致主从同步停止。

    Last_SQL_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.

    原因

    报错信息为从库“无法读取relay log 里的条目”,可能原因为master库的binglog错误,或slave库的中继日志错误。或者为网络问题及bug原因。一般是由于网络故障或slave库压力过大,导致relay-log格式错误造成的。找到当前已经同步的时间点,重新设置主从同步,就会产生新的中继日志,恢复正常。

    解决方法

    1.从"show slave status\G"的输出中,找到如下信息:

    Relay_Master_Log_File: dd-bin.002540 //slave库已读取的master的binlog

    Exec_Master_Log_Pos: 950583017 //在slave上已经执行的position位置点

    2.停掉slave,以slave已经读取的binlog文件,和已经执行的position为起点,重新设置同步。会产生新的中继日志,问题解决。(不需要指定host,user,password等,默认使用当前已经设置好的)

    mysql>stop slave;

    mysql>change master to master_log_file='dd-bin.002540',master_log_pos=950583017;

    mysql>start slave;

    Slave_IO_Running: No:“Could not find first log file name in binary log index file”的解决办法

    数据库主从出错:

    Slave_IO_Running: No 一方面原因是因为网络通信的问题也有可能是日志读取错误的问题。

    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'

    解决办法:

    1.从机器停止slave:mysql> slave stop;

    2.到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

    3.刷新日志:mysql> flush logs;

    4.因为刷新日志file的位置会+1,即File变成为:mysqld-bin.000011

    5.马上到slave执行

    mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysqld-bin.000011',MASTER_LOG_POS=106;

    mysql> slave start;

    mysql> show slave status\G;

  • 相关阅读:
    【递归】拆分自然数
    HDOJ3068最长回文
    博弈论——尼姆博奕
    vijos P1047最小公倍数
    Eular质数筛法-hiho一下 第九十三周
    hdoj-5652 India and China Origins二分+bfs
    hdoj-1166排兵布阵 简单的树状数组
    hdoj-5641 king's phone
    hdoj-1548简单的bfs题目
    命令中"|"的意义
  • 原文地址:https://www.cnblogs.com/aslanvon/p/15049418.html
Copyright © 2011-2022 走看看