测试环境
Mysql版本: 5.7.22
安装环境: docker

show slave status错误记录

一、Slave_IO_Running: Connecting

error connecting to master ‘wen@127.18.0.2:3306’ - retry-time: 60

解决方法:
第一次用docker运行两个mysql,但没有考虑到容器间的通信问题,用network解决后,错误提示消除

错误日志

  mysql> show slave status \G
  *************************** 1. row ***************************
                 Slave_IO_State: Connecting to master
                    Master_Host: 127.18.0.2
                    Master_User: wen
                    Master_Port: 3306
                  Connect_Retry: 60
                Master_Log_File: mysql-bin.000003
            Read_Master_Log_Pos: 154
                 Relay_Log_File: 72e00ec79233-relay-bin.000001
                  Relay_Log_Pos: 4
          Relay_Master_Log_File: mysql-bin.000003
               Slave_IO_Running: Connecting
              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: 154
                Relay_Log_Space: 154
                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: 1045
                  Last_IO_Error: error connecting to master 'wen@127.18.0.2:3306' - retry-time: 60  retries: 1

二、Slave_IO_Running: No

Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).

解决方法:
提示server-id必须不相同,但用show variables like 'server_id’查看主从的server_id并不一样,但一直提示该错误。
后来实在想事到办法,重新新建了两个msyql服务,配置文件也进行修改,启动后该提示消除。
报错之前主从配置文件
主数据库配置文件:

    [mysqld]
    pid-file  = /var/run/mysqld/mysqld.pid
    socket    = /var/run/mysqld/mysqld.sock
    datadir   = /var/lib/mysql
    #log-error  = /var/log/mysql/error.log
    # By default we only accept connections from localhost
    #bind-address = 127.0.0.1
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0

    character_set_server = utf8
    init_connect = 'SET NAMES utf8'
    log-bin=mysql-bin #启动二进制日志系统
    server-id=109 #本机数据库ID
    binlog-do-db=test #二进制需要同步的数据库名
    log-bin=/var/log/mysql/updatelog 
    binlog-ignore-db=mysql #避免同步mysql用户配置,以免不必要的麻烦

从数据库配置文件

  [mysqld]
    pid-file  = /var/run/mysqld/mysqld.pid
    socket    = /var/run/mysqld/mysqld.sock
    datadir   = /var/lib/mysql
    #log-error  = /var/log/mysql/error.log
    # By default we only accept connections from localhost
    #bind-address = 127.0.0.1
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0

    character_set_server = utf8
    init_connect = 'SET NAMES utf8'
    log-bin=mysql-bin
    server-id=117
    master-host=172.18.0.2
    master-user=root
    master-password=123456
    master-port=3306
    master-connect-retry=60
    replicate-ignore-db=mysql
    replicate-do-db=test

正常运行主从数据库配置文件
主数据库配置文件:

   [mysqld]
    pid-file  = /var/run/mysqld/mysqld.pid
    socket    = /var/run/mysqld/mysqld.sock
    datadir   = /var/lib/mysql
    #log-error  = /var/log/mysql/error.log
    # By default we only accept connections from localhost
    #bind-address = 127.0.0.1
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0

    character_set_server = utf8
    init_connect = 'SET NAMES utf8'
    log-bin=mysql-bin #启动二进制日志系统
    server-id=1 #本机数据库ID
    #binlog-do-db=test #二进制需要同步的数据库名
    #log-bin=/var/log/mysql/updatelog 
    #binlog-ignore-db=mysql #避免同步mysql用户配置,以免不必要的麻烦

从数据库配置文件

[mysqld]
    pid-file  = /var/run/mysqld/mysqld.pid
    socket    = /var/run/mysqld/mysqld.sock
    datadir   = /var/lib/mysql
    #log-error  = /var/log/mysql/error.log
    # By default we only accept connections from localhost
    #bind-address = 127.0.0.1
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0

    character_set_server = utf8
    init_connect = 'SET NAMES utf8'
    log-bin=mysql-bin
    server-id=2
    #master-host=172.18.0.2
    #master-user=root
    #master-password=123456
    #master-port=3306
    #master-connect-retry=60
    #replicate-ignore-db=mysql
    #replicate-do-db=test

错误日志

    mysql> show slave status \G
    *************************** 1. row ***************************
                   Slave_IO_State: 
                      Master_Host: 127.18.0.2
                      Master_User: root
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: 
              Read_Master_Log_Pos: 4
                   Relay_Log_File: 619018ffa281-relay-bin.000002
                    Relay_Log_Pos: 4
            Relay_Master_Log_File: 
                 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: 0
                  Relay_Log_Space: 154
                  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
    Master_SSL_Verify_Server_Cert: No
                    Last_IO_Errno: 1593
                    Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).

三、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、首先在从数据库上执行 stop slave;
2、刷新主数据库logs;flush logs;刷新binlog日志,刷新后的日志会+1

mysql> show master status\G;
  *************************** 1. row ***************************
               File: mysql-bin.000004
           Position: 154
       Binlog_Do_DB: 
   Binlog_Ignore_DB: 
  Executed_Gtid_Set: 
  1 row in set (0.01 sec)

  ERROR: 
  No query specified

  mysql> flush logs;
  Query OK, 0 rows affected (0.11 sec)

3、再次查看master状态

mysql> show master status\G;
  *************************** 1. row ***************************
               File: mysql-bin.000005
           Position: 155
       Binlog_Do_DB: 
   Binlog_Ignore_DB: 
  Executed_Gtid_Set: 
  1 row in set (0.01 sec)

  ERROR: 
  No query specified

4、设备从数据库master信息
输入CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000005’,MASTER_LOG_POS=155;
执行start slave;

  mysql> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 172.17.0.5
                      Master_User: slave_user
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000004
              Read_Master_Log_Pos: 319
                   Relay_Log_File: d6dffe0be29f-relay-bin.000002
                    Relay_Log_Pos: 485
            Relay_Master_Log_File: mysql-bin.000004
                 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: 319
                  Relay_Log_Space: 699
                  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
    Master_SSL_Verify_Server_Cert: No
                    Last_IO_Errno: 0
                    Last_IO_Error: 
                   Last_SQL_Errno: 0
                   Last_SQL_Error: 
      Replicate_Ignore_Server_Ids: 
                 Master_Server_Id: 1
                      Master_UUID: 3f1867a3-b9b4-11e8-bdc9-0242ac110005
                 Master_Info_File: /var/lib/mysql/master.info
                        SQL_Delay: 0
              SQL_Remaining_Delay: NULL
          Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
               Master_Retry_Count: 86400
                      Master_Bind: 
          Last_IO_Error_Timestamp: 
         Last_SQL_Error_Timestamp: 
                   Master_SSL_Crl: 
               Master_SSL_Crlpath: 
               Retrieved_Gtid_Set: 
                Executed_Gtid_Set: 
                    Auto_Position: 0
             Replicate_Rewrite_DB: 
                     Channel_Name: 
               Master_TLS_Version: 
    1 row in set (0.00 sec)

    ERROR: 
    No query specified

错误日志

 *************************** 1. row ***************************
                   Slave_IO_State: 
                      Master_Host: 172.17.0.5
                      Master_User: slave_user
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: master-bin.000003
              Read_Master_Log_Pos: 154
                   Relay_Log_File: d6dffe0be29f-relay-bin.000001
                    Relay_Log_Pos: 4
            Relay_Master_Log_File: master-bin.000003
                 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: 154
                  Relay_Log_Space: 154
                  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'
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐