熟练使用 information_schema库里的表
显示在库里的表,实际上是View;
select * from CHARACTER_SETS;
select * from COLLATIONS;
select * from `COLUMNS`;
select * from `TABLES`;
select * from USER_PRIVILEGES;
select * from `PARTITIONS`;
select * from INNODB_INDEXES;
information_schema.TABLES
统计数据库和表的大小,主要是借助 information_schema 库的 TABLES 表:
SELECT
*
FROM
information_schema.TABLES;
主要字段分别是:
TABLE_SCHEMA :数据库名
TABLE_NAME:表名
ENGINE:所使用的存储引擎
TABLES_ROWS:记录数
DATA_LENGTH:数据大小,以字节为单位
INDEX_LENGTH:索引大小,以字节为单位
查看该数据库实例下所有库大小(MB为单位)
SELECT
sum( data_length )/ 1024 / 1024 AS data_length,
sum( index_length )/ 1024 / 1024 AS index_length,
sum( data_length + index_length )/ 1024 / 1024 AS sum
FROM
information_schema.TABLES;
查看该实例下各个库大小(MB为单位)
SELECT
table_schema,
sum( data_length + index_length )/ 1024 / 1024 AS total_mb,
sum( data_length )/ 1024 / 1024 AS data_mb,
sum( index_length )/ 1024 / 1024 AS index_mb,
count(*) AS TABLES,
curdate() AS today
FROM
information_schema.TABLES
GROUP BY
table_schema
ORDER BY
2 DESC;
查看表大小(MB为单位)
SELECT
concat( round( sum( data_length / 1024 / 1024 ), 2 ), 'MB' ) AS data_length_MB,
concat( round( sum( index_length / 1024 / 1024 ), 2 ), 'MB' ) AS index_length_MB
FROM
information_schema.TABLES
WHERE
table_schema = '数据库名'
AND table_name = '表名';
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/155592.html