43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
检查MySQL数据库中的所有表
|
|
"""
|
|
import pymysql
|
|
|
|
def check_mysql_tables():
|
|
"""检查MySQL数据库表"""
|
|
print("=== 检查MySQL数据库中的所有表 ===")
|
|
|
|
try:
|
|
# 连接到MySQL数据库
|
|
connection = pymysql.connect(
|
|
host='localhost',
|
|
user='root',
|
|
password='taiyi1224',
|
|
database='baoxiang',
|
|
charset='utf8mb4'
|
|
)
|
|
|
|
with connection.cursor() as cursor:
|
|
# 查询所有表
|
|
cursor.execute("SHOW TABLES")
|
|
tables = cursor.fetchall()
|
|
|
|
print("数据库表:")
|
|
for table in tables:
|
|
print(f"- {table[0]}")
|
|
|
|
# 查看表结构
|
|
cursor.execute(f"DESCRIBE {table[0]}")
|
|
columns = cursor.fetchall()
|
|
print(f" 结构:")
|
|
for column in columns:
|
|
print(f" - {column[0]} ({column[1]})")
|
|
print()
|
|
|
|
connection.close()
|
|
except Exception as e:
|
|
print(f"MySQL数据库连接错误: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
check_mysql_tables() |