python slave status 2
#!/usr/bin/env python
import MySQLdb
import contextlib
@contextlib.contextmanager
def mysql(Host,Port,User,Password,Database):
conn = MySQLdb.connect(host=Host, port=Port, user=User, passwd=Password, db=Database)
#cursor = conn.cursor()
cursor = conn.cursor(MySQLdb.cursors.DictCursor);
try:
yield cursor;
finally:
conn.commit();
cursor.close();
conn.close();
def execSql(excelSql):
hosts = {0:{"host":"192.168.1.140","port":3306,"user":"root","Password":"123456","database":"test"},
1:{"host":"192.168.1.141","port":3306,"user":"root","Password":"123456","database":"test"}}
for idx in hosts:
#print(hosts[idx]["host"])
ip = hosts[idx]["host"]
port = hosts[idx]["port"]
user = hosts[idx]["user"]
password = hosts[idx]["Password"]
database = hosts[idx]["database"]
with mysql(ip,port,user,password,database) as cursor:
sql = excelSql
cursor.execute(sql)
rows = cursor.fetchall()
if len(rows)>0:
Master_Host = rows[0]["Master_Host"]
SQL_THREAD = rows[0]["Slave_SQL_Running"]
IO_THREAD = rows[0]["Slave_IO_Running"]
LAST_ERROR= rows[0]["Last_Error"]
Slave_SQL_RunStatus= rows[0]["Slave_SQL_Running_State"]
Master_InforStatus = rows[0]["Master_Info_File"]
print("-------DataServer:%s------" % ip)
print("relp Master Host: %s" % Master_Host)
print("repl SQL Thread: %s" % SQL_THREAD)
print("repl IO Thread: %s" % IO_THREAD)
print("Mrepl Last error: %s" % LAST_ERROR)
print("Slave SQLRunStatus: %s" % Slave_SQL_RunStatus)
print("Master_InfoStatus: %s" % Master_InforStatus)
print("\n")
if __name__ == "__main__":
sql = "show slave status"
execSql(sql)
python slave status 2的更多相关文章
- Python执行show slave status输出的两个格式
1.元组的方式 输出格式如下: ('Waiting for master to send event', '10.75.19.79', 'mysqlsync', 5580L, 60L, 'mysql- ...
- python show slave status
#!/usr/bin/env python import MySQLdbimport contextlib @contextlib.contextmanagerdef mysql(Host,Port, ...
- show master/slave status求根溯源
show master/slave status分别是查看主数据库以及副数据库的状态,是一种能查看主从复制运行情况的方式. 这里仅仅讨论linux下的nysql5.7.13版本的执行情况 一.show ...
- 两主机搭建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 ...
- 从show slave status 中判断mysql同步状态
slave status 中检查同步状态: 1.sql线程和io线程显示yes Slave_IO_Running: Yes Slave_SQL_Running: Yes 2. Master_Log_F ...
- show slave status中的log_file / log_pos
在MySQL的master-slave或dual master的架构中,我们经常使用show slave status命令来查看复制状态. 这里涉及几个重要的日志文件和位置: Master_Log_F ...
- mysql----show slave status \G 说明
show slave status \G 可以用来查看mysql 的复制状态,有些列名所表达的意思不太明确,现整理如下: 1. Slave_IO_State:ID线程的状态,如果master 的所有变 ...
- [置顶] 两主机搭建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 master / slave status 命令参数
一.show master status 二.show slave status Slave_IO_State SHOW PROCESSLIST输出的State字段的拷贝.SHOW PROCESSLI ...
随机推荐
- HDU 1251 统计难题(字典树 裸题 链表做法)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- python自定义异常抛出接受多个数值
在使用Python的时候,有时候想自己自定义异常错误,同时抛出多个参数,比如对数据库查找一条数据,如果没有找到,返回 {"errCode":"-1", &quo ...
- 2.22 JS处理富文本
2.22 JS处理富文本 前言 <富文本>这篇解决了富文本上iframe问题,其实没什么特别之处,主要是iframe的切换,本篇讲解通过js的方法处理富文本上iframe的问题一.加 ...
- RPi 3B 无线连接配置
/********************************************************************** * RPi 3B 无线连接配置 * 说明: * 树莓派3 ...
- 【leetcode】290. Word Pattern
problem 290. Word Pattern 多理解理解题意!!! 不过博主还是不理解,应该比较的是单词的首字母和pattern的顺序是否一致.疑惑!知道的可以分享一下下哈- 之前理解有误,应该 ...
- 【leetcode】53-MaximumSubarray
problem MaximumSubarray code class Solution { public: int maxSubArray(vector<int>& nums) { ...
- Python之路,第二十篇:Python入门与基础20
python3 面向对象4 supper 函数 supper(type, obj) 返回绑定超类的实例(要求obj必须为type类型的实例) supper() 返回绑定的超类的实例,等同于(cl ...
- Python之路,第七篇:Python入门与基础7
python3 元组 (tuple) 元组是不可改变的序列, 同list 一样, 元组可以存放任意的值: 表示方法: 用小括号()括起来: 单个元素括起来后加逗号(,)区分单个对象还是元组: 创建空 ...
- pandas-cheat-sheet
- [LeetCode&Python] Problem 836. Rectangle Overlap
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...