如何知道 MySQL 复制是否正常工作?

Mar*_*ler 4 mysql replication mysql-5.5

我正在从 MySQL v 5.5.50 主服务器复制到 RDS 中托管的 MySQL v 5.5.46 从服务器。我已经按照 AWS 文档了解了如何严格执行此操作,将转储文件导入到从属服务器中,并在CALL mysql.rds_set_external_master...几天前运行命令来开始操作。

我的SHOW MASTER STATUS;结果是:

+---------------------+----------+--------------+------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-binlog.000023 | 48684053 |              |                  |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

我的SHOW SLAVE STATUS \G;结果是:

*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: [master host IP here]
                  Master_User: [local replication user here]
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-binlog.000023
          Read_Master_Log_Pos: 53052514
               Relay_Log_File: relaylog.000007
                Relay_Log_Pos: 81145300
        Relay_Master_Log_File: mysql-binlog.000017
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table: mysql.rds_sysinfo,mysql.rds_history,mysql.rds_replication_status
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1016905328
              Relay_Log_Space: 5695987840
              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: 394467
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: 21033229
1 row in set (0.12 sec)
Run Code Online (Sandbox Code Playgroud)

最后,唯一可见的两行相关行(我的客户没有睡眠)SHOW FULL PROCESSLIST;是:

*************************** 2. row ***************************
     Id: 207
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 361292
  State: Waiting for master to send event
   Info: NULL
*************************** 3. row ***************************
     Id: 208
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 394904
  State: Reading event from the relay log
   Info: NULL
Run Code Online (Sandbox Code Playgroud)

我试图确认事物是否真的在复制,因为Seconds_Behind_Master价值越来越大。不过,Master_Log_File身价已经上升到与大师不相上下的地步了。

Exec_Master_Log_Pos并且Relay_Log_Pos已经很长时间没有改变了。然而,Read_Master_Log_Pos一直在增长。

我在 RDS 提供给我的日志文件中没有发现错误,进程启动时没有警告或错误。

有没有办法可以判断是否存在某种错误,以及如何从中恢复?

(* 不能 100% 确定这有多长,而是以小时而不是秒来衡量)

更新

我运行了从站停止命令,然后运行了从站启动命令,在日志中,我得到以下内容:

160817 10:39:04 [Note] Slave SQL thread exiting, replication stopped in log 'mysql-binlog.000018' at position 72335184
160817 10:39:04 [ERROR] Error reading packet from server: Lost connection to MySQL server during query ( server_errno=2013)
160817 10:39:04 [Note] Slave I/O thread killed while reading event
160817 10:39:04 [Note] Slave I/O thread exiting, read up to log 'mysql-binlog.000025', position 74416238
160817 10:39:22 [Note] Slave SQL thread initialized, starting replication in log 'mysql-binlog.000018' at position 72335184, relay log '/rdsdbdata/log/relaylog/relaylog.000010' position: 72335333
160817 10:39:22 [Note] Slave I/O thread: connected to master '[replication user]@[server ip]:3306',replication started in log 'mysql-binlog.000025' at position 74416238
Run Code Online (Sandbox Code Playgroud)

所以我看不出有什么不妥的地方。该值Seconds_Behind_Master仍在上升,并且在我的进程列表等中仍然没有显示任何单独的命令。

Ric*_*mes 6

这两个...Running值表示YES;这通常足以说明一切都很好。然而Seconds_Behind_Master: 394467却很可怕。那11个小时!

运行测试:在 Master 上执行CREATE DATABASE dummy;,然后查看 Slave 上是否存在。(你可能需要root两次。)

在某些情况下,Seconds_Behind_Master会在 0 和某个大值之间跳动。那是侥幸。观察一段时间就知道是这样的。