How to monitor mysql master-slave replication using python

Source: Internet
Author: User
This article describes how to monitor mysql master-slave replication using python to check MySQL master-slave replication,

Cur.exe cute ("show slave status;") cannot use cur.exe cute ("show slave status \ G ;")

Result = cur. fetchall ()

Returns a binary array.

Result [0] indicates the status of the show slave status when the result is returned.

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 ')

Cur = conn. cursor ()

Cur.exe cute ("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 t 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 t Exception, e:

Print Exception, ":", e

# Return status

Go = final_check_mysql ()

The above describes how to monitor mysql master-slave replication using python. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.