首先查询所有数据库占用磁盘空间大小的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
TRUNCATE (index_length / 1024 / 1024, 2) AS
FROM
information_schema. TABLES
WHERE
table_schema =
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