MySql 查询数据库中所有表名, 所占空间,索引空间等

1.MySql 查询数据库中所有表名

https://www.cnblogs.com/BenWong/p/3996061.html

查询数据库中所有表名

select table_name from information_schema.tables where table_schema='csdb' and table_type='base table';

 

查询指定数据库中指定表的所有字段名column_name

select column_name from information_schema.columns where table_schema='csdb' and table_name='users'

2.查看Mysql库,表所占磁盘空间大小

https://www.cnblogs.com/reyes/p/6408821.html

查询库

 

SELECT
    CONCAT(
        TRUNCATE (
            SUM(data_length) / 1024 / 1024,
            2
        ),
        'MB'
    ) AS data_size,
    CONCAT(
        TRUNCATE (
            SUM(max_data_length) / 1024 / 1024,
            2
        ),
        'MB'
    ) AS max_data_size,
    CONCAT(
        TRUNCATE (SUM(data_free) / 1024 / 1024, 2),
        'MB'
    ) AS data_free,
    CONCAT(
        TRUNCATE (
            SUM(index_length) / 1024 / 1024,
            2
        ),
        'MB'
    ) AS index_size
FROM
    information_schema. TABLES
WHERE
    TABLE_SCHEMA = 'activiti';

查询表
SELECT
    CONCAT(
        TRUNCATE (
            SUM(data_length) / 1024 / 1024,
            2
        ),
        'MB'
    ) AS data_size,
    CONCAT(
        TRUNCATE (
            SUM(max_data_length) / 1024 / 1024,
            2
        ),
        'MB'
    ) AS max_data_size,
    CONCAT(
        TRUNCATE (SUM(data_free) / 1024 / 1024, 2),
        'MB'
    ) AS data_free,
    CONCAT(
        TRUNCATE (
            SUM(index_length) / 1024 / 1024,
            2
        ),
        'MB'
    ) AS index_size
FROM
    information_schema. TABLES
WHERE
    TABLE_NAME = 'act_hi_comment';

 

 

3.查看mysql库大小,表大小,索引大小
https://www.cnblogs.com/lukcyjane/p/3849354.html

查看所有库的大小
use information_schema;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES;

查看指定库的大小
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES where table_schema='jishi';

查看指定库的指定表的大小
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES where table_schema='jishi' and table_name='a_ya';

查看指定库的索引大小
SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM TABLES  WHERE table_schema = 'jishi'; 

查看指定库的指定表的索引大小
SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM TABLES  WHERE table_schema = 'test' and table_name='a_yuser'; 

查看一个库中的情况
SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows',
CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size',
CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'test';

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(mysql,table,index,空间)