0
点赞
收藏
分享

微信扫一扫

MySQL数据容量查询


MySQL数据容量查询

  • ​​1. 各数据库容量​​
  • ​​2. 指定数据库各表容量​​
  • ​​3. 指定数据库容量​​
  • ​​4. 各数据库表容量​​

参考文档: ​​information_schema​​ 这里面存放着数据库各表基本信息

MySQL数据容量查询_容量统计

1. 各数据库容量

SELECT
table_schema AS '数据库',
sum( table_rows ) AS '记录数',
sum(
TRUNCATE ( data_length / 1024 / 1024, 2 )) AS '数据容量(MB)',
sum(
TRUNCATE ( index_length / 1024 / 1024, 2 )) AS '索引容量(MB)'
FROM
information_schema.TABLES
GROUP BY
table_schema
ORDER BY
sum( data_length ) DESC,
sum( index_length ) DESC;

MySQL数据容量查询_数据库_02

2. 指定数据库各表容量

SELECT
table_schema AS '数据库',
table_name AS '表名',
table_rows AS '记录数',
TRUNCATE ( data_length / 1024 / 1024, 2 ) AS '数据容量(MB)',
TRUNCATE ( index_length / 1024 / 1024, 2 ) AS '索引容量(MB)'
FROM
information_schema.TABLES
WHERE
table_schema = 'zabbix'
ORDER BY
data_length DESC,
index_length DESC;

MySQL数据容量查询_sql_03

3. 指定数据库容量

SELECT
table_schema AS '数据库',
sum( table_rows ) AS '记录数',
sum(
TRUNCATE ( data_length / 1024 / 1024, 2 )) AS '数据容量(MB)',
sum(
TRUNCATE ( index_length / 1024 / 1024, 2 )) AS '索引容量(MB)'
FROM
information_schema.TABLES
WHERE
table_schema = 'mysql';

MySQL数据容量查询_mysql_04

4. 各数据库表容量

SELECT
table_schema AS '数据库',
table_name AS '表名',
table_rows AS '记录数',
TRUNCATE ( data_length / 1024 / 1024, 2 ) AS '数据容量(MB)',
TRUNCATE ( index_length / 1024 / 1024, 2 ) AS '索引容量(MB)'
FROM
information_schema.TABLES
ORDER BY
data_length DESC,
index_length DESC;

MySQL数据容量查询_数据库_05


举报

相关推荐

0 条评论