Mysql show slave status 的研究
来源:互联网 发布:吕中 奚美娟 知乎 编辑:程序博客网 时间:2024/06/10 23:22
我们使用 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 主库当前正在记录的binlog4040 binlog中的position10.37.129.3 主库的ipkiwi 用于slave同步的用户oracle 用户的密码3306 主库的数据库使用的端口1800.000eecf3d7b-b4d0-11e4-a343-001c42e98b7886400该部分内容会随着从库应用主库的进程而不停的更新下面就是发生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: NULLMaster_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_errorroot@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: NULLMaster_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
- Mysql show slave status 的研究
- show slave status 各个参数的解释 -- mysql
- show slave status 各个参数的解释 -- mysql
- show slave status \G 的详细解释
- show slave status 各个参数的解释
- show slave status 解释
- SHOW SLAVE STATUS 详解
- show slave status 详解
- SHOW SLAVE STATUS详解
- SHOW SLAVE STATUS
- SHOW SLAVE STATUS 详解
- Show slave status 详解
- show slave status
- SHOW SLAVE STATUS 详解
- SHOW SLAVE STATUS 详解
- MySQL的SHOW STATUS
- mysql主从复制之show slave status解析
- MySQL多实例从库show slave status卡死
- 一个很简单的javascript问题,看你能否答对
- 利用boost获取时间并格式化
- 一小时搞定DIV+CSS布局-固定页面开度布局
- 我bug心得
- deadline_timer
- Mysql show slave status 的研究
- LeetCode 35 Search Insert Position 二叉查找相关(一)
- C#中的定义修饰符总结
- 学习shader之前必须知道的东西之计算机图形学(一)渲染管线
- C语言之结构体浅谈
- boost锁的概述
- IOS SEL (@selector) 原理及使用总结(一)
- 郭靖和黄蓉竟然是这样死的!---某些人最近看了柴静的《穹顶之下》后狂喷她,这些人可能就是本文中的甲乙丙丁
- C++ Primer Plus第六版编程练习6.9解答