要求
查询指定数据库所有表名
实例
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pymysql.cursors
dbname = 'test'
connection = pymysql.connect(host='localhost',
user='root',
password='password88',
db=dbname,
charset='utf8',
cursorclass=pymysql.cursors.DictCursor)
results =[]
try:
with connection.cursor() as cursor:
sql = '''SHOW TABLES'''
cursor.execute(sql)
result = cursor.fetchall()
for i in range(len(result)):
results.append(result[i]['Tables_in_test'])
finally:
connection.close()
print(results)