Home MySQL查询数据库的数据量大小
Post
Cancel

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

查询数据库最大连接数

1
show variables like '%max_connections%';

查询数据库连接超时时间单位(s)

1
Show variables like 'wait_timeout';

查询各个数据库量的大小

1
2
3
4
5
6
7
select
  TABLE_SCHEMA,
  CONCAT(ROUND(SUM(DATA_LENGTH / 1024 / 1024), 2), 'MB') dbsize
from
  information_schema.tables
group by
  TABLE_SCHEMA;

查询指定数据库量的大小

1
2
3
4
5
6
7
select
  '数据库大小',
  CONCAT(ROUND(SUM(DATA_LENGTH / 1024 / 1024), 2), 'MB') dbsize
from
  information_schema.tables
where
  table_schema = '库名';

查询某个表的大小

1
2
3
4
5
6
7
8
select
  '表大小',
  CONCAT(ROUND(SUM(DATA_LENGTH / 1024 / 1024), 2), 'MB') tbsize
from
  information_schema.tables
where
  table_schema = '库名'
  and table_name = '表名';

查询各个表的大小

1
2
3
4
5
6
7
8
9
10
select
  table_name,
  '表大小',
  CONCAT(ROUND(SUM(DATA_LENGTH / 1024 / 1024), 2), 'MB') tbsize
from
  information_schema.tables
where
  table_schema = '库名'
group by
  table_name;
This post is licensed under CC BY 4.0 by the author.