如何获取mysql数据库的大小?
假设目标数据库名为“v3”。
答案 0 :(得分:1013)
运行此查询,您可能会得到您正在寻找的内容:
SELECT table_schema "DB Name",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
此查询来自the mysql forums,其中提供了更全面的说明。
答案 1 :(得分:42)
可以使用以下MySQL命令
来确定SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema
结果
Database Size (MB)
db1 11.75678253
db2 9.53125000
test 50.78547382
以GB结果
SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 / 1024 AS "Size (GB)" FROM information_schema.TABLES GROUP BY table_schema
答案 2 :(得分:25)
或者,您可以直接跳转到数据目录并检查v3.myd,v3的组合大小。 myi和v3。 frm文件(用于myisam)或v3.idb& v3.frm(对于innodb)。
答案 3 :(得分:25)
答案 4 :(得分:11)
以MB格式获得结果:
SELECT
SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024), 2)) AS "SIZE IN MB"
FROM INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = "SCHEMA-NAME";
以GB获得结果:
SELECT
SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 / 1024), 2)) AS "SIZE IN GB"
FROM INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = "SCHEMA-NAME";
答案 5 :(得分:8)
mysqldiskusage --server=root:MyPassword@localhost pics
+----------+----------------+
| db_name | total |
+----------+----------------+
| pics | 1,179,131,029 |
+----------+----------------+
如果没有安装,可以通过安装应由大多数主要发行版打包的mysql-utils
软件包来安装。
答案 6 :(得分:2)
进入mysql数据目录并运行du -h --max-depth = 1 | grep databasename
答案 7 :(得分:2)
如果要对所有数据库大小的列表进行排序,可以使用:
SELECT *
FROM (SELECT table_schema AS `DB Name`,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS `DB Size in MB`
FROM information_schema.tables
GROUP BY `DB Name`) AS tmp_table
ORDER BY `DB Size in MB` DESC;
答案 8 :(得分:1)
使用
mysql -u username -p
用于显示单个数据库及其表的大小的命令,以MB为单位。
SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "database_name"
ORDER BY (data_length + index_length) DESC;
将database_name更改为您的数据库
命令以显示所有数据库及其 大小以MB为单位。
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;
答案 9 :(得分:-3)
如果您正在寻找如何获取 Postgres 数据库的大小:
SELECT pg_size_pretty(pg_database_size('my_database_name'));