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. TABLESGROUP BY table_schemaORDER BY sum(data_length) DESC, sum(index_length) DESC;+--------------------+-----------+------------------+------------------+| 数据库 | 记录数 | 数据容量(MB) | 索引容量(MB) |+--------------------+-----------+------------------+------------------+| cok_db1 | 72137886 | 16776.96 | 10350.47 || cok_db1_test | 133689 | 52.21 | 25.17 || cokdb_global | 134266 | 29.67 | 1.18 || mysql | 4961 | 1.87 | 0.00 || cokdb_pay | 525 | 0.26 | 0.00 || information_schema | NULL | 0.10 | 0.00 || test | 1 | 0.06 | 0.00 || innodb_memcache | 4 | 0.03 | 0.00 || performance_schema | 1357095 | 0.00 | 0.00 || sys | NULL | NULL | NULL |+--------------------+-----------+------------------+------------------+10 rows in set (0.94 sec)
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
ORDER BY
data_length DESC,
index_length DESC;
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 = 'cok_db1';
+-----------+-----------+------------------+------------------+
| 数据库 | 记录数 | 数据容量(MB) | 索引容量(MB) |
+-----------+-----------+------------------+------------------+
| cok_db1 | 72137887 | 16776.96 | 10350.47 |
+-----------+-----------+------------------+------------------+
1 row in set (0.04 sec)
4.查看mysql库各表容量大小
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 = 'cok_db1'
ORDER BY
data_length DESC,
index_length DESC;
