mysql show slave status 无记录_Mysql show slave status 的研究

我们使用 show slave status \G 来查看

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 10.37.129.3

Master_User: kiwi

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000010 记录的是当前主库正在记录的binlog

Read_Master_Log_Pos: 3938 当前binlog中的position

Relay_Log_File: mysqld-relay-bin.000039 slave_io_thread 线程从主库的binlog中读取写入到relay_binlog

Relay_Log_Pos: 499 写入到的relay_log 的位置

Relay_Master_Log_File: mysql-bin.000010 当前从库应用到的binlog日志

Slave_IO_Running: Yes slave_io_thread 线程当前是否正在从主库的binlog中挖掘日志(后面有详细的分析)

Slave_SQL_Running: Yes slave_sql_thread 现在当前是否正在应用relay_binlog中的内容

Replicate_Do_DB: 需要复制的数据库(配置此参数,就是只复制存在再参数中的数据库)

Replicate_Ignore_DB: test 忽略复制的数据库(配置次参数,就是忽略掉参数中的db的sql应用)

Replicate_Do_Table: 需要复制的表

Replicate_Ignore_Table: 忽略复制的表

Replicate_Wild_Do_Table: 需要复制的表,可以使用通配符,复制某个数据库下的全部的表

Replicate_Wild_Ignore_Table: 忽略复制的表,可以使用通配符,忽略复制某个数据库下的全部的表

Last_Errno: 0 反映的是最后一个报错的信息,可能是io_error,也可能是sql_error

Last_Error: 反映的是最后一个报错的具体的信息

Skip_Counter: 0

Exec_Master_Log_Pos: 3938 当前从库应用到的binlog日志中的具体的位置

Relay_Log_Space: 673

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 这部分会显示如果io_thread 有问题的错误

Last_IO_Error:

Last_SQL_Errno: 0 这部分会显示如果sql_thread 有问题的错误

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID: eecf3d7b-b4d0-11e4-a343-001c42e98b78

Master_Info_File: /opt/mysql/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp: 发生io_error的时间戳

Last_SQL_Error_Timestamp: 发生sql_error的时间戳

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

其中在master.info 中,在这个二进制文件中记录了

mysql-bin.000010 主库当前正在记录的binlog

4040 binlog中的position

10.37.129.3 主库的ip

kiwi 用于slave同步的用户

oracle 用户的密码

3306 主库的数据库使用的端口

1800.000

eecf3d7b-b4d0-11e4-a343-001c42e98b78

86400

该部分内容会随着从库应用主库的进程而不停的更新

下面就是发生sql_error时的状况

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 10.37.129.3

Master_User: kiwi

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000010

Read_Master_Log_Pos: 4249

Relay_Log_File: mysqld-relay-bin.000041

Relay_Log_Pos: 385

Relay_Master_Log_File: mysql-bin.000010

Slave_IO_Running: Yes

Slave_SQL_Running: No

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 1146

Last_Error: Error 'Table 'test.t3' doesn't exist' on query. Default database: 'test'. Query: 'insert into t3 values(10)'

Skip_Counter: 0

Exec_Master_Log_Pos: 4040

Relay_Log_Space: 768

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

Last_IO_Error:

Last_SQL_Errno: 1146

Last_SQL_Error: Error 'Table 'test.t3' doesn't exist' on query. Default database: 'test'. Query: 'insert into t3 values(10)'

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID: eecf3d7b-b4d0-11e4-a343-001c42e98b78

Master_Info_File: /opt/mysql/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State:

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp: 150304 16:10:22

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

如何解决sql_error的问题呢,从库其实就相当于oracle的逻辑备库的概念,从主库挖掘sql语句然后到从库上面进行应用,而出现sql_error,唯一的原因就是主从的数据不一致了,上我们通常的有三种方法来进行解决

1 手动的分析主库哪儿的数据不一致了,然后在从库修补数据

2 使用pt_table_sync 工具来同步主从的数据

3 在确认无影响的情况下,我们可以手动的跳过一些事务来保证从库的继续运行。

这部分我将单独写一篇文章讲述如何处理从库的sql_error

root@localhost:test:04:42:50> show slave status \G;

*************************** 1. row ***************************

Slave_IO_State: Connecting to master

Master_Host: 10.37.129.3

Master_User: kiwi

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000010

Read_Master_Log_Pos: 5085

Relay_Log_File: mysqld-relay-bin.000001

Relay_Log_Pos: 4

Relay_Master_Log_File: mysql-bin.000010

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

Relay_Log_Space: 120

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 'kiwi@10.37.129.3:3306' - retry-time: 60 retries: 1

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID: eecf3d7b-b4d0-11e4-a343-001c42e98b78

Master_Info_File: /opt/mysql/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp: 150304 16:42:50

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

一般造成io_error问题的很多是由于网络故障,导致从库无法连接主库,或者防火墙问题,或者用于进行同步的user的密码被修改这些问题,这些问题就要具体问题具体分析了

Seconds_Behind_Master,该值作为判断主从延时的指标,那么它又是怎么得到这个值的呢,同时,它为什么又受到很多人的质疑?

Seconds_Behind_Master是通过比较sql_thread执行的event的timestamp和io_thread复制好的 event的timestamp(简写为ts)进行比较,而得到的这么一个差值。我们都知道的relay-log和主库的bin-log里面的内容完全一 样,在记录sql语句的同时会被记录上当时的ts,所以比较参考的值来自于binlog,其实主从没有必要与NTP进行同步,也就是说无需保证主从时钟的 一致。你也会发现,其实比较真正是发生在io_thread与sql_thread之间,而io_thread才真正与主库有关联,于是,问题就出来了, 当主库I/O负载很大或是网络阻塞,io_thread不能及时复制binlog(没有中断,也在复制),而sql_thread一直都能跟上 io_thread的脚本,这时Seconds_Behind_Master的值是0,也就是我们认为的无延时,但是,实际上不是,你懂得。这也就是为什 么大家要批判用这个参数来监控数据库是否发生延时不准的原因,但是这个值并不是总是不准,如果当io_thread与master网络很好的情况下,那么 该值也是很有价值的。(就好比:妈–儿子–媳妇的关系,妈与儿子亲人,媳妇和儿子也亲人,不见得媳妇与妈就很亲。开个玩笑:-)之前,提到 Seconds_Behind_Master这个参数会有负值出现,我们已经知道该值是io_thread的最近跟新的ts与sql_thread执行到 的ts差值,前者始终是大于后者的,唯一的肯能就是某个event的ts发生了错误,比之前的小了,那么当这种情况发生时,负值出现就成为可能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值