要获取表中的磁盘空间存储,可以使用以下方法:
SELECT table_name, ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
ORDER BY (data_length + index_length) DESC;
将"your_database_name"替换为你的数据库名称。这将返回每个表的名称和以MB为单位的大小。
import pymysql
# 连接数据库
conn = pymysql.connect(host='your_host', port=3306, user='your_username', password='your_password', db='your_database')
# 创建游标对象
cursor = conn.cursor()
# 执行SQL查询
cursor.execute("SELECT table_name, ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)' FROM information_schema.tables WHERE table_schema = 'your_database_name' ORDER BY (data_length + index_length) DESC")
# 获取查询结果
results = cursor.fetchall()
# 打印结果
for row in results:
print(row[0], ":", row[1], "MB")
# 关闭游标和数据库连接
cursor.close()
conn.close()
将"your_host"、"your_username"、"your_password"和"your_database"替换为你的数据库连接信息。这将打印出每个表的名称和大小。
请确保安装了pymysql模块,可以使用以下命令进行安装:
pip install pymysql
上一篇:表中的表 pdfmake
下一篇:表中的DI数值