要查看 MySQL 数据库的大小,可以通过查询系统表 information_schema.tables 来实现,以下是具体方法:
- 查看所有数据库的大小
sql
SELECT
table_schema AS '数据库名',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS '数据库大小(MB)'
FROM
information_schema.tables
GROUP BY
table_schema
ORDER BY
SUM(data_length + index_length) DESC; - 查看指定数据库的大小
将 your_database_name 替换为实际数据库名:
sql
SELECT
table_schema AS '数据库名',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS '数据库大小(MB)'
FROM
information_schema.tables
WHERE
table_schema = 'your_database_name'; - 查看指定数据库中各表的大小
sql
SELECT
table_name AS '表名',
ROUND(data_length / 1024 / 1024, 2) AS '数据大小(MB)',
ROUND(index_length / 1024 / 1024, 2) AS '索引大小(MB)',
ROUND((data_length + index_length) / 1024 / 1024, 2) AS '总大小(MB)'
FROM
information_schema.tables
WHERE
table_schema = 'your_database_name'
ORDER BY
(data_length + index_length) DESC;
说明:
data_length:表数据的大小
index_length:表索引的大小
计算结果默认以 MB 为单位,如需 GB 可再除以 1024
这些查询会遍历所有表,对于大型数据库可能需要一定时间
以上就是关于mysql查看数据库大小的介绍。还有一款非常便捷的MYSQL导出、导入备份工具也运用的很不错,“80KM-mysql备份工具”。 可定时备份、异地备份,MYSQL导出导入。可本地连接LINUX里的MYSQL,简单便捷。
通过以上方法可以清晰地了解数据库及其中表的存储占用情况。