扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
python版本2.6.6
为企业提供成都网站制作、成都网站设计、网站优化、营销型网站、竞价托管、品牌运营等营销获客服务。创新互联建站拥有网络营销运营团队,以丰富的互联网营销经验助力企业精准获客,真正落地解决中小企业营销获客难题,做到“让获客更简单”。自创立至今,成功用技术实力解决了企业“网站建设、网络品牌塑造、网络营销”三大难题,同时降低了营销成本,提高了有效客户转化率,获得了众多企业客户的高度认可!
#!/usr/bin/python
import MySQLdb
def check_mysql():
status = True
try:
conn=MySQLdb.connect(host='172.7.10.8',user='summer',passwd='summer',db='cms')
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()
status = True
if io_thread == "Yes" and sql_thread == "Yes":
print '2'
status = True
else:
print '0'
status = False
except Exception,e:
print Exception,":",e
go = check_mysql()
听大神的修改后代码:
#!/usr/bin/python
import MySQLdb
def check_mysql():
try:
conn=MySQLdb.connect(host='172.7.10.8',user='summer',passwd='summer',
db='cms')
cur=conn.cursor(MySQLdb.cursors.DictCursor)
cur.execute('show slave status')
result=cur.fetchall()
if result is None:
raise EnvironmentError('result is None')
slave_status=result[0]
io_thread=slave_status.get('Slave_IO_Running')
sql_thread=slave_status.get('Slave_SQL_Running')
if io_thread == "Yes" and sql_thread == "Yes":
print 'it is status ok'
else:
print 'io_status is %s \nsql_status is %s' %(io_thread,sql_thread)
finally:
cur.close()
conn.close()
if __name__ == '__main__':
check_mysql()
~
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流