为什么mysql主从复制,从服务器的Time值诡异?

作者:吴炳锡 来源:http://www.mysqlsupport.cn/ 联系方式:select unhex(‘777562696E67786940676D61696C2E636F6D’); 载请注明作/译者和出处,并且不能用于商业用途,违者必究。

    从服务器show slave status\G;状态正常,show processlist;这个时候我观察到一个复制线程的Time值为4294967295,这个数字为2^32-1,数据比较特殊,然后我再show processlist;Time成为0,再查看,Time值变为1,等会再查看的时候Time值又变为4294967295,反正TIME值就是在 4294967295,0,1之间变化,show slave status\G,从服务器正常在运作。
mysql> show processlist;
+——-+————-+———–+——+———+————+———————————————————————–+——————+
| Id    | User        | Host      | db   | Command | Time       | State                                                                 | Info             |
+——-+————-+———–+——+———+————+———————————————————————–+——————+
|     4 | system user |           | NULL | Connect |    2950273 | Waiting for master to send event                                      | NULL             |
|     5 | system user |           | NULL | Connect | 4294967295 | Has read all relay log; waiting for the slave I/O thread to update it | NULL             |
| 14814 | root        | localhost | NULL | Query   |          0 | NULL                                                                  | show processlist |
+——-+————-+———–+——+———+————+——————————————————————

mysql> show processlist;
+——-+————-+———–+——+———+———+———————————————————————–+——————+
| Id    | User        | Host      | db   | Command | Time    | State                                                                 | Info             |
+——-+————-+———–+——+———+———+———————————————————————–+——————+
|     4 | system user |           | NULL | Connect | 2950543 | Waiting for master to send event                                      | NULL             |
|     5 | system user |           | NULL | Connect |       0 | Has read all relay log; waiting for the slave I/O thread to update it | NULL             |
| 14814 | root        | localhost | NULL | Query   |       0 | NULL                                                                  | show processlist |
+——-+————-+———–+——+———+———+———————————————————————-

mysql> show processlist;
+——-+————-+———–+——+———+———+———————————————————————–+——————+
| Id    | User        | Host      | db   | Command | Time    | State                                                                 | Info             |
+——-+————-+———–+——+———+———+———————————————————————–+——————+
|     4 | system user |           | NULL | Connect | 2950574 | Waiting for master to send event                                      | NULL             |
|     5 | system user |           | NULL | Connect |       1 | Has read all relay log; waiting for the slave I/O thread to update it | NULL             |
| 14814 | root        | localhost | NULL | Query   |       0 | NULL                                                                  | show processlist |
+——-+————-+———–+——+———+———+———————————————————————-

有两个原因:
第一个: 这个情况我以前在4.X以前遇到过。后来升级到4.1后就没这个问题了。如果你的版本低于这个版本,有可能会这种情况。
第二个:有可能是你的网络不稳定。导至从服务器连接Master不稳定,从而返还的时间比较不准确。或是你的Master太忙了,Slave得到的时间有可能超时了。

这个时间表示:
Slave的SQL线程连接上Master的时间点和实际进行的SQL点的时间差别。例,当Slave和Master断开时间为30分钟,再时连上,这个时间为1800。
另一方面网络不稳也会出现问题。