打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
python 实践1 python连接库

#!/usr/local/bin/python 
# -*- coding: UTF-8 -*- 
import MySQLdb
import threading
# author:xx
# time: 2014/8/20
BIGCOUNT=0
COUNT=0

def check(ip,port_2):
    global BIGCOUNT
    global COUNT
    BIGCOUNT+=1
    try:
        conn = MySQLdb.connect(host=ip,user="xxx",port=port_2,passwd='xx',charset='utf8')
        cur = conn.cursor()
        cur.execute("show variables like '%slave_exec_mode%';")
        result=cur.fetchall()
        for i in result:
            print ip,port_2,i[1]
        
            if i[1] != "SMART":
                COUNT+=1 
                print "IP:"+ ip , "port:"+str(port_2) ,i[1]
        cur.close()
        conn.close()
    except Exception , ex: 
        pass

def checkmeta():
    conn = MySQLdb.connect(host="xxx,user="rdsrnd",passwd="xxx",db="xx",charset='utf8')
    cur = conn.cursor()
    sql = """
SELECT
AND t1.type = 'x' limit 10 ; 
          """
    cur.execute(sql)
    result=cur.fetchall()
    for i in result:
        check(i[0],i[1])
    print "共扫描mysql实例:" +str(BIGCOUNT) ,  "参数不是force的有:" +str(COUNT)
    cur.close()
    conn.close() 


for i in xrange(1): 
    m = threading.Thread(target=checkmeta)
#   m.setDaemon(True)
    m.start();


#if __name__=="__main__":
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Python学习之路(二):MySQLdb的几种安装方式,以及用Python测试连接MySql
[Python]Python连接MySQL的实例代码
Postfix邮箱【十五】全局地址本自动生成脚本
MYSQL Python 入门教程
python 连接各类主流数据库简单示例
python3使用PyMysql连接mysql数据库实例
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服