mysql查看数据库、表大小、磁盘空间占用以及一些常用mysql代码,持续更新ing
在MySQL中,您可以使用一些内置的函数和命令来查看数据库、表的大小以及磁盘空间的占用情况。
- 查看数据库大小:
SELECT table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
- 查看单个表的大小:
SELECT table_name AS "Table",
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;
- 查看数据库占用的磁盘空间:
SELECT
CONCAT(ROUND(SUM(data_length)/1024/1024, 2), ' MB') AS data_size,
CONCAT(ROUND(SUM(index_length)/1024/1024, 2), ' MB') AS index_size
FROM information_schema.TABLES
WHERE table_schema = "your_database_name";
请将your_database_name
替换为您的数据库名称。
注意:这些命令可能需要您具有相应的权限才能执行。
评论已关闭