python读取MYSQL表的记录数

import pymysql
connect = pymysql.connect(user = 'm',
            password = 'M',
            db = 'x',
            host = 'rm',
            port = 3306,
            charset = 'utf8'
            )
con = connect.cursor()
bu=0
buu=0
def du(ab):
    sql="select count(*) from {} where bzz='0'".format(ab)
    try:
        count1=con.execute(sql)
        connect.commit()
    except:
        connect.commit()
    count2=con.fetchall()
    if count2[0][0]<10:
        sql1="update bm51 set bzz='0'"
        con.execute(sql1)
        connect.commit()
        
        

 

posted @ 2021-11-03 16:57  myrj  阅读(841)  评论(0编辑  收藏  举报