import pymysql
db = pymysql.connect(host='',
port=,
user='',
password='')
cursor = db.cursor()
def get_table_list(in_db, in_table_name):
"""
获取数据库中的表数量
"""
sql = f'''show tables from {in_db};'''
cursor.execute(sql)
data = cursor.fetchall()
table_list = []
for d in data:
if in_table_name in d[0]:
table_list.append(d[0])
print(f'一共有{len(table_list)}张{in_table_name}')
return table_list
get_table_list(database, table)