MySQL数据库大小、数据条数查询

查询MySQL数据库的总数据大小

SELECT table_schema AS "数据库",
       SUM(data_length + index_length) / 1024 / 1024 AS "总大小(MB)"
FROM information_schema.tables
GROUP BY table_schema;

大小单位改成GB

SELECT table_schema AS "数据库",
       ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS "总大小(GB)"
FROM information_schema.tables
GROUP BY table_schema;

查询每个表的大小
your_database_name替换成你的数据库名称

SELECT 
    table_name AS "表名",
    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;

查询数据库总数据条数

SELECT SUM(TABLE_ROWS) AS "总数据条数"
FROM information_schema.tables
WHERE TABLE_SCHEMA = 'your_database_name';

查询数据库每个表的数据条数

SELECT 
    table_name AS "表名",
    table_rows AS "数据条数"
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
ORDER BY table_rows DESC;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。