当前位置:嗨网首页>书籍在线阅读

16-查看从库状态

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

为了防止复制过程中出现故障从而导致复制进程停止,我们需要经常检查从库的复制状态。一般使用 show slave status命令来检查,如下所示:

mysql> show slave status \G

1. row

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.7.200

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000039

Read_Master_Log_Pos: 382

Relay_Log_File: master1-relay-bin.000002

Relay_Log_Pos: 523

Relay_Master_Log_File: mysql-bin.000039

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: 382

Relay_Log_Space: 523

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

1 row in set (0.00 sec)

在显示的这些信息中,我们主要关心“Slave_IO_Running”和“Slave_SQL_Running”这两个进程状态是否是“yes”,这两个进程的含义分别如下。

Slave_IO_Running:此进程负责从库(Slave)从主库(Master)上读取BINLOG日志,并写入从库上的中继日志中。

Slave_SQL_Running:此进程负责读取并且执行中继日志中的BINLOG日志。

只要其中有一个进程的状态是no,则表示复制进程停止,错误原因可以从“Last_Errno”字段的值中看到。

除了查看上面的信息,用户还可以通过这个命令了解从库的配置情况以及当前和主库的同步情况,包括指向哪个主库、主库的端口、复制使用的用户、当前日志恢复到的位置等,这些信息都是记录在从库这一端的,主库上并没有相应的信息。