Answers:
运行此查询,您可能会找到想要的东西:
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;
该查询来自mysql论坛,那里提供了更全面的说明。
FROM
和GROUP
行之间:where table_schema='DATABASE_NAME'
-用DATABASE_NAME
您的数据库替换。
Syntax error: {column title} (double quoted text) is not valid input here.
错误。列标题应打勾。即Database Name
。
可以通过使用以下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
或者,您可以直接跳到数据目录并检查v3.myd,v3的组合大小。myi和v3。frm文件(用于myisam)或v3.idb和v3.frm(用于innodb)。
要获得以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";
首次使用登录MySQL
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;