20 lines
585 B
Python
20 lines
585 B
Python
#!/usr/bin/env python3
|
|
"""检查数据库表行数"""
|
|
import MySQLdb
|
|
from app_secrets import DATABASE_HOST, DATABASE_PORT, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME
|
|
|
|
conn = MySQLdb.connect(
|
|
host=DATABASE_HOST, port=int(DATABASE_PORT),
|
|
user=DATABASE_USER, password=DATABASE_PASSWORD,
|
|
database=DATABASE_NAME
|
|
)
|
|
cursor = conn.cursor()
|
|
cursor.execute(
|
|
"SELECT TABLE_NAME, TABLE_ROWS FROM information_schema.TABLES "
|
|
"WHERE TABLE_SCHEMA = %s ORDER BY TABLE_NAME",
|
|
[DATABASE_NAME]
|
|
)
|
|
for row in cursor.fetchall():
|
|
print(f"{row[0]:40s} {row[1]}")
|
|
conn.close()
|