Python执行show slave status输出的两个格式
1、元组的方式
输出格式如下:
('Waiting for master to send event', '10.75.19.79', 'mysqlsync', 5580L, 60L, 'mysql-bin.000050', 300947174L, 'relay-bin.000054', 210L, 'mysql-bin.000050', 'Yes', 'Yes', '', '', '', '', '', '', 0L, '', 0L, 300947174L, 463L, 'None', '', 0L, 'No', '', '', '', '', '', 0L, 'No', 0L, '', 0L, '', '', 28585580L)
对应的python脚本:
def get_all_slave_lag(self):
for slave in self.slaves_list:
conn=MySQLdb.connect(host=slave,user=self.user,passwd=self.password,port=self.port,db=self.db)
cursor=conn.cursor()
cursor.execute("show slave status")
result=cursor.fetchall()
for row in result:
print row
self.lags.append(row[32])
cursor.close()
conn.close()
有个问题:
例如获取second_behind_master的值时候,需要考虑对应的顺序,例如5.5版本,对应的顺序为32,可能其他版本的就不一样,需要考虑版本信息。
2、字典模式输出
输出格式如下:
{'Replicate_Wild_Do_Table': '', 'Master_SSL_CA_Path': '', 'Last_Error': '', 'Until_Log_File': '', 'Seconds_Behind_Master': 0L, 'Master_User': 'mysqlsync', 'Master_Port': 5580L, 'Until_Log_Pos': 0L, 'Master_Log_File': 'mysql-bin.000050', 'Read_Master_Log_Pos': 300947174L, 'Replicate_Do_DB': '', 'Master_SSL_Verify_Server_Cert': 'No', 'Exec_Master_Log_Pos': 300947174L, 'Replicate_Ignore_Server_Ids': '', 'Replicate_Ignore_Table': '', 'Master_Server_Id': 28585580L, 'Relay_Log_Space': 463L, 'Last_SQL_Error': '', 'Relay_Master_Log_File': 'mysql-bin.000050', 'Master_SSL_Allowed': 'No', 'Master_SSL_CA_File': '', 'Slave_IO_State': 'Waiting for master to send event', 'Relay_Log_File': 'relay-bin.000054', 'Replicate_Ignore_DB': '', 'Last_IO_Error': '', 'Until_Condition': 'None', 'Replicate_Do_Table': '', 'Last_Errno': 0L, 'Master_Host': '10.75.19.79', 'Master_SSL_Key': '', 'Skip_Counter': 0L, 'Slave_SQL_Running': 'Yes', 'Relay_Log_Pos': 210L, 'Master_SSL_Cert': '', 'Last_IO_Errno': 0L, 'Slave_IO_Running': 'Yes', 'Connect_Retry': 60L, 'Last_SQL_Errno': 0L, 'Replicate_Wild_Ignore_Table': '', 'Master_SSL_Cipher': ''}
对应代码如下:
def get_all_slave_lag(self):
for slave in self.slaves_list:
conn=MySQLdb.connect(host=slave,user=self.user,passwd=self.password,port=self.port,db=self.db)
cursor=conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor.execute("show slave status")
result=cursor.fetchall()
for row in result:
print row
self.lags.append(row['Seconds_Behind_Master'])
cursor.close()
conn.close()
这样比较方便且通用,不用考虑格式问题。
本例子是对应show slave status是这样使用,对于show status以及show variables 也一样处理
Python执行show slave status输出的两个格式的更多相关文章
- Python执行系统命令并获得输出的几种方法
[root@a upfc]# ./ffmpeg-linux64-v3.3.1 -i a.mp3 ffmpeg version N-86111-ga441aa90e8-static http://joh ...
- python执行linux shell管道输出内容
干净不留痕,用过都说好. echo "print 1+1" |python
- 两主机搭建MySQL主从复制后,show slave status显示:Last_IO_Error: error connecting to master ……
两台主机A.B搭建mysql主从复制关系(A为master,B为slave)后,在slave上执行show slave status,结果中显示Last_IO_Error: error connect ...
- [置顶] 两主机搭建MySQL主从复制后,show slave status显示:Last_IO_Error: error connecting to master ……
两台主机A.B搭建mysql主从复制关系(A为master,B为slave)后,在slave上执行show slave status,结果中显示Last_IO_Error: error connect ...
- mysql----show slave status \G 说明
show slave status \G 可以用来查看mysql 的复制状态,有些列名所表达的意思不太明确,现整理如下: 1. Slave_IO_State:ID线程的状态,如果master 的所有变 ...
- show master status, show slave status中的Executed_Gtid_Set
slave 如果server是slave节点,在server上执行show master staus与show slave status显示的Executed_Gtid_Set是一样的. slave也 ...
- mysql命令 show slave status\G;命令输出详解
show slave status\G; 命令输出详解 mysql> show slave status\G; *************************** . row ******* ...
- python show slave status
#!/usr/bin/env python import MySQLdbimport contextlib @contextlib.contextmanagerdef mysql(Host,Port, ...
- python slave status 2
#!/usr/bin/env python import MySQLdbimport contextlib @contextlib.contextmanagerdef mysql(Host,Port, ...
随机推荐
- JavaWeb之response响应中文乱码问题
response向页面响应中文乱码问题 字节流 * 有可能乱码,与中文转换成字节数组.浏览器打开的默认字符编码有关 * 解决方式:将中文转成字节数组的时候和浏览器默认打开的时候采用的字符集一致 re ...
- 浅谈script标签中的async和defer
script标签用于加载脚本与执行脚本,在前端开发中可以说是非常重要的标签了.直接使用script脚本的话,html会按照顺序来加载并执行脚本,在脚本加载&执行的过程中,会阻塞后续的DOM渲染 ...
- 【JDK1.8】Java 8源码阅读汇总
一.前言 万丈高楼平地起,相信要想学好java,仅仅掌握基础的语法是远远不够的,从今天起,笔者将和园友们一起阅读jdk1.8的源码,并将阅读重点放在常见的诸如collection集合以及concu ...
- js 查询 添加 删除 练习
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- MQTT——入门介绍
笔者相信大家对HTTP一定不能陌生."HTTP协议的三次握手四次挥手"相信也略有耳闻.HTTP协议的优势相信大家都明白.不然他不会这流行.然而这并不能忽略他的缺点.最大的特点就是无 ...
- MySQL简概
MySQL简介与概要 mysql 是一个小型关系型数据库管理系统,开发者为瑞典MySQL AB公司,现在已经被sun公司收购,支持FreeBSD.Linux.MAC.windows等多种操作系统.相比 ...
- C# WinForm DataGridView让DataPropertyName支持复杂属性
首先给Grid添加BindingSource,类型为BindingForForm2.或者设置Grid的DataSource为IEnumerable<BindingForForm2>. Bi ...
- (MariaDB)MySQL数据类型详解和存储机制
html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...
- C#导出.csv格式的excel表
.cs文件直接贴代码: using System; using System.Collections.Generic; using System.Data; using System.IO; usin ...
- LINUX 笔记-free命令
free命令可以显示Linux系统中空闲的.已用的物理内存及swap内存,及被内核使用的buffer. focus@ubuntu:~$ free -h total used free shared b ...