Home > Backend Development > Python Tutorial > How to use python to monitor the master-slave replication of mysql

How to use python to monitor the master-slave replication of mysql

高洛峰
Release: 2017-03-22 11:55:20
Original
2317 people have browsed it

Use python to check the master-slave replication of MySQL.

One thing to note is that cur.execute("show slave status;") cannot be used cur.execute("show slave status\G;")

result = cur.fetchall()

Returns a binary array

result[0] returns the entire show slave status status information.

result[0][n] Returns a specific item.

The python code is as follows:

#!/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')

                                                                                                                                    using using ’ using ’s ’ using ’s ’ s using ’s ’ s ’ ‐ to ​0] [10]

SQL_THREAD = Result [0] [11]

## 0

__thread, SQL_THREAD

## Cur.Close ()

                  conn.close()

                                      ’ s ’s ’s ’s ’s ’s ‐ except Exception

-t's-,e:

                                    ’ out out out out off out out out out out out of ’s' ’s ’ ’ off through ‐ through ‐‐‐‐‐‐‐‐ ‐ ‐ ‐ ‐ ‐           to

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

# Exception Exception E:

PRINT Exception, ":", E

Return

Status

## = = Final_check_mysql ()

The above is the detailed content of How to use python to monitor the master-slave replication of mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template