直接上代码
select table_schema as '表名字',
concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as '数据使用/MB',
concat(round(sum(INDEX_LENGTH/1024/1024),2),'MB') as '索引使用/MB',
concat(round((sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024,2),'MB') as '总数据容量/MB'
from information_schema.TABLES
group by table_schema;
MySQL自带访问数据库元数据的方式:
information_schema.tables 获取所有数据库
#查看Mysql所有数据库中数据表的名称、数据库注释、创建时间(mysql自带的和自定义的都会查询出来)
select table_name, table_comment, create_time, update_time
from information_schema.tables
table_schema 是数据库的名称
table_name 是具体的表名。
table_type 表的类型。
#获取某个数据库中的所有表的表名、表类型、引擎等等
select table_name, table_type, engine
from information_schema.tables
where table_schema = '{数据库名}'
order by table_name desc;
select database() 获取当前数据库下的所有表
#获取 当前数据库下的所有表名、表注释、创建及更新时间。
select table_name, table_comment, create_time, update_time
from information schema.tables
where table_schema (select database());
concat(str1, str2, str3)
将多个字符串连接成一个字符串
注意其中有一个null,返回值也是null。
data_length : 存储数据大小
index_length : 索引数据大小
评论