MySQL 如何获取mysql数据库的大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1733507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:30:26  来源:igfitidea点击:

How to get size of mysql database?

mysqldatabase

提问by Newbie

How to get size of a mysql database?
Suppose the target database is called "v3".

如何获取mysql数据库的大小?
假设目标数据库名为“v3”。

回答by Brian Willis

Run this query and you'll probably get what you're looking for:

运行这个查询,你可能会得到你要找的东西:

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; 

This query comes from the mysql forums, where there are more comprehensive instructions available.

此查询来自mysql 论坛,那里有更全面的说明。

回答by Nadeem0035

It can be determined by using following MySQL command

可以通过使用以下 MySQL 命令来确定

SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema

Result

结果

Database    Size (MB)
db1         11.75678253
db2         9.53125000
test        50.78547382

Get result in GB

以 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

回答by Joel

Alternatively, if you are using phpMyAdmin, you can take a look at the sum of the table sizes in the footer of your database structuretab. The actual database size may be slightly over this size, however it appears to be consistent with the table_schemamethod mentioned above.

或者,如果您使用的是phpMyAdmin,您可以查看数据库structure选项卡页脚中的表大小总和。实际的数据库大小可能会略大于这个大小,但是看起来和table_schema上面提到的方法是一致的。

Screen-shot :

截屏 :

enter image description here

在此处输入图片说明

回答by Joel

Alternatively you can directly jump into data directory and check for combined size of v3.myd, v3. myi and v3. frm files (for myisam) or v3.idb & v3.frm (for innodb).

或者,您可以直接跳转到数据目录并检查 v3.myd、v3 的组合大小。myi 和 v3。frm 文件(对于 myisam)或 v3.idb & v3.frm(对于 innodb)。

回答by williambarau

To get a result in MB:

要获得以 MB 为单位的结果:

SELECT
SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024), 2)) AS "SIZE IN MB"
FROM INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = "SCHEMA-NAME";

To get a result in GB:

要获得以 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";

回答by Rick James

mysqldiskusage  --server=root:MyPassword@localhost  pics

+----------+----------------+
| db_name  |         total  |
+----------+----------------+
| pics     | 1,179,131,029  |
+----------+----------------+

If not installed, this can be installed by installing the mysql-utilspackage which should be packaged by most major distributions.

如果没有安装,可以通过安装mysql-utils大多数主要发行版应该打包的包来安装。

回答by Hiren Parghi

First login to MySQL using

第一次登录到 MySQL 使用

mysql -u username -p

mysql -u username -p

Command to Display the size of a single Database along with its table in MB.

命令以显示单个数据库的大小及其表(以 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;

Change database_name to your Database

将 database_name 更改为您的数据库

Command to Display all the Databases with its size in MB.

命令显示所有数据库及其大小(以 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;

回答by Evan Haston

Go into the mysql data directory and run du -h --max-depth=1 | grep databasename

进入mysql数据目录并运行 du -h --max-depth=1 | grep databasename