1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
-- 查看数据库大小
SELECT
table_schema AS '数据库名',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS '大小(MB)',
ROUND(SUM(data_length) / 1024 / 1024, 2) AS '数据大小(MB)',
ROUND(SUM(index_length) / 1024 / 1024, 2) AS '索引大小(MB)'
FROM information_schema.tables
GROUP BY table_schema
ORDER BY SUM(data_length + index_length) DESC;
-- 查看数据库大小 - 含表数量
SELECT
table_schema AS 'Database',
COUNT(*) AS 'Tables',
ROUND(SUM(data_length) / 1024 / 1024, 2) AS 'Data Size (MB)',
ROUND(SUM(index_length) / 1024 / 1024, 2) AS 'Index Size (MB)',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Total Size (MB)',
ROUND(SUM(data_free) / 1024 / 1024, 2) AS 'Free Space (MB)'
FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
GROUP BY table_schema
ORDER BY SUM(data_length + index_length) DESC;
-- 查询表行数 和 数据大小 和 索引大小
SELECT table_schema, table_name, table_rows,
data_length/1024/1024 as SIZE_T_MB,
index_length/1024/1024 as SIZE_I_MB
FROM information_schema.tables WHERE table_schema = 'mytest';
-- 查询自增id的使用情况
select
table_schema,table_name,engine,Auto_increment
from
information_schema.tables
where
INFORMATION_SCHEMA.tables.TABLE_SCHEMA not in ("information_schema","performance_schema","sys","mysql");
|