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 ‐‐‐‐‐‐‐‐ ‐ ‐ ‐ ‐ ‐ totry:
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:
ReturnStatus
## = = 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!