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!