阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

使用Python监控MySQL主从复制

135次阅读
没有评论

共计 1429 个字符,预计需要花费 4 分钟才能阅读完成。

利用 Python 来检查 MySQL 的主从复制,有一个注意点是,cur.execute(“show slave status;”) 不能用 cur.execute(“show slave status\G;”)

result = cur.fetchall()

返回的是个二元数组

result[0] 返回时整个 show slave status 状态信息。

result[0][n] 返回具体的某一项。

python 代码如下:

#!/usr/bin/env python

#-*- coding: utf-8 -*-

import MySQLdb, socket, paramiko,sys, os,datetime

def final_check_mysql ():

status = True

      try:

                conn=MySQLdb.connect(host=’192.168.3.10′,user=’root’,passwd=’Xp29at5F37′,db=’test’)

                cur=conn.cursor()

                cur.execute(“show slave status;”)

result = cur.fetchall()

io_thread= result[0][10]

sql_thread= result[0][11]

print io_thread,sql_thread

                cur.close()

                conn.close()

        except Exception,e:

                print Exception,”:”,e

status = True

try:

if io_thread == “Yes” and sql_thread == “Yes”:

              print ‘MySQL master/slave replication status is successfully’

        else:

              print ‘MySQL Master/Slave replication fail,Please check it’

              status = False

except Exception,e:

              print Exception,”:”,e

#return status

go=final_check_mysql()

MySQL 5.7 Docker 主从复制架构搭建 http://www.linuxidc.com/Linux/2016-11/136998.htm

MySQL 主从复制操作  http://www.linuxidc.com/Linux/2017-02/141172.htm

MySQL 主从复制数据一致性校验和修复方法及自动化实现  http://www.linuxidc.com/Linux/2017-02/141114.htm

MySQL 主从复制常见错误及解决方法  http://www.linuxidc.com/Linux/2017-02/141059.htm

MySQL 主从复制,读写分离 (mysql-proxy) 及双主结构完整构建过程  http://www.linuxidc.com/Linux/2016-11/137635.htm

CentOS 搭建 MySQL 主从复制,读写分离  http://www.linuxidc.com/Linux/2016-09/135121.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141891.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计1429字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中