数据库相关容量

368 阅读1分钟

首先查询所有数据库占用磁盘空间大小的SQL语句如下:

select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),’ MB’) as data_size, 
concat(truncate(sum(index_length)/1024/1024,2),’MB’) as index_size 
from information_schema.tables 
group by TABLE_SCHEMA 
order by data_length desc;

然后是查询单个数据库里面各个表所占磁盘空间大小包括其索引的大小,SQL语句如下:

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 = 'quotation' and table_name = 't_quotation_cache_data'
ORDER BY
    table_rows DESC;

mysql 查看数据库中所有表的记录数

use information_schema; 
select table_name,table_rows from tables 
where TABLE_SCHEMA = 'dbname' 
order by table_rows desc;

导出数据库文件,并忽略某张表

/usr/bin/mysqldump --set-gtid-purged=OFF -h127.0.0.1 -uroot -p123456 dbname --ignore-table=dbname.tb1
--ignore-table=dbname.tb2 > ./db_files/dsp.sql