import pandas as pd
import numpy as np
from pymysql import connect
conn = connect (host=' 10. 10. 169. 57', user=' ******', password=' ****', charset=' utf8')
list1 =["ZSH D32D10JJJCZ-SDSH-XZCF",
"ZSHD42 D16JJJCZ_SHBJSJ",
"SH D52 D20JJC TYJ",
"ZSH D52 D22JJJo2_YSSJ"]
tablesl=[]
#创建数据量列表
suml=[]
for name_dbl in list1:
sql_tabname ="select table_name FROM information_schema.`TABLES` WHERE TABLE_SCHEMA='"name_db1+"':"
print (sql_tabname)
temp=pd.read_sql(sql_tabname,conn)
#print (type(temp))
name_tablesl=list(temp['table_name'])
for n in name_tables1:
sql =' SBLECT COUNt(1) FROM '+ name_db1+'.'+n+';'
shu = pd.read_sql(sql,conn)
shu=list(shu['COUNt(1)'])
# print (Shu)
tablesl.append(n)
suml.append(shu)
huizongl = pd.DataFrame(zip(tablesl,suml),columns=['数据表','数据条数'])
huizongl ['数据条数'] =huizong1['数据条数].apply(lambda x: str(x).replace('[',"").replace (']',""))
huizongl.head()
huizongl.to_excel (r'c: \Users \Administrator\Desktop\统计表名及数据条数0320.xlsx',index=False)