MySQL 复制:Master 秒后超高

Mat*_*ías 8 mysql replication

我已经为我的生产数据库设置了一个从数据库服务器,但是当我检查 show slave status 时,我注意到在 master 后面几秒钟内有一个超级大的数字。

这是输出:

           Slave_IO_State: Waiting for master to send event
              Master_Host: 1.2.3.4
              Master_User: replicator
              Master_Port: 3306
            Connect_Retry: 60
          Master_Log_File: mysql-bin.000173
      Read_Master_Log_Pos: 15909435
           Relay_Log_File: mysqld-relay-bin.000079
            Relay_Log_Pos: 91173356
    Relay_Master_Log_File: mysql-bin.000093
         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: 91173210
          Relay_Log_Space: 8179978166
          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: 486330
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
1 row in set (0.00 sec)

ERROR: 
No query specified
Run Code Online (Sandbox Code Playgroud)

然后当我运行 SHOW PROCESSLIST 时,我看到线程的时间与后面以秒为单位指示的时间相匹配:

mysql> SHOW PROCESSLIST;

| 40 | system user |           | NULL | Connect |  66530 | Waiting for master to send event | NULL             |
| 41 | system user |           | NULL | Connect | 486330 | Reading event from the relay log | NULL             |
| 45 | root        | localhost | NULL | Query   |      0 | NULL                             | SHOW PROCESSLIST |
Run Code Online (Sandbox Code Playgroud)

那个时间正在下降,慢慢地。Read_Master_Log_Pos、Relay_Log_Pos、Exec_Master_Log_Pos 和 Relay_Log_Space 一直在变化。

我还检查了时间/日期,并且两台服务器都处于同步状态。

在大师方面:

mysql> SHOW PROCESSLIST;

| 66739 | replicator | 1.2.3.5:52884 | NULL                | Binlog Dump |    65671 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL             
Run Code Online (Sandbox Code Playgroud)

并显示从属主机看起来是空的...

mysql> SHOW SLAVE HOSTS;
+-----------+------+------+-----------+
| Server_id | Host | Port | Master_id |
+-----------+------+------+-----------+
|         2 |      | 3306 |         1 |
+-----------+------+------+-----------+
1 row in set (0.00 sec)

mysql> 
Run Code Online (Sandbox Code Playgroud)

那么这里究竟发生了什么?看起来从站实际上已连接并正在工作,但是非常非常慢?有人可以给我一些关于如何对此进行更多调试的提示吗?服务器在 95% 时相当空闲。

Rol*_*DBA 15

当你看到Seconds_Behind_Master那么高时,我会看以下内容:

Relay_Log_Space: 8179978166
Run Code Online (Sandbox Code Playgroud)

您有 7.6182GB 的中继日志需要处理。

Master_Log_File: mysql-bin.000173
Relay_Master_Log_File: mysql-bin.000093
Run Code Online (Sandbox Code Playgroud)

这告诉我您已阅读最多mysql-bin.000173,但您目前正在处理mysql-bin.000093.

这也告诉我您在 Master 上有大约 80 个二进制日志,每个大约 100 MB。

Seconds_Behind_Master只是 NOW() 减去在mysql-bin.000093(Relay_Master_Log_File) 位置91173210(Exec_Master_Log_Pos)设置的 TIMESTAMP 。

只要 Slave_SQL_Thread 为 Yes,中继日志就会得到处理

  • Relay_Log_Space 每次中继日志完成时都会减少
  • Exec_Master_Log_Pos 将增加直到当前中继日志完成,然后重置到下一个中​​继的开始
  • TIMESTAMP 不断增加,这使得Seconds_Behind_Master减少(NOW() 减去在 Relay_Master_Log_File 位置 Exec_Master_Log_Pos 设置的 TIMESTAMP)

这是当复制关闭 486330 秒(5 天 15 小时 5 分 29 秒)并且您运行时发生的情况 start slave;

看看你的SHOW PROCESSLIST;. IO 线程已启动 66530 秒(18 小时 28 分 50 秒)。这意味着某人或某事在 18 小时 28 分 50 秒前开始复制。

您在问题中表示您已经为生产服务器设置了复制。这意味着您在 5 天 15 小时 5 分 29 秒前运行了 mysqldump,并在 18 小时 28 分 50 秒前开始从生产主机复制。

如果您在从 Master 获得 mysqldump 的同一天设置了 Slave,那么复制负载会少很多。尽管如此,复制工作正常提供,Slave_IO_Thread并且Slave_SQL_Thread都说Yes.