虚拟库字段讲解
#查看INFORMATION_SCHEMA的表信息
DESC information_schema.tables;
重要列:
TABLE_SCHEMA #表所在的库
TABLE_NAME #表名
ENGINE #表的存储引擎
TABLE_ROWS #表的行数
DATA_LENGTH #表数据行占用的字节数
AVG_ROW_LENGTH #平均行长度
INDEX_LENGTH #索引的长度
案例
例1:查询mysql库中有哪些表
方法一:从硬盘上查找
show tables from mysql;
方法二:从内存中查找
select table_name from information_schema.tables where table_schema='mysql';
例2:统计mysql库的表数量
select count(table_name) from information_schema.tables where table_schema='mysql';
例3:统计当前数据库服务器每个库的表数量
select
table_schema as 库名,
count(table_name) as 表数量
from
information_schema.tables
group by
table_schema;
例4:统计当前数据库服务器库的数量
select
count(distinct table_schema) as 库数量
from
information_schema.tables;
注意事项:
1.在企业应用中,应排除系统库,需要在where条件中增加如下下配置
where table_schema not in ('mysql','sys','information_schema','performance_schema')
2.要解决交互问题,能直接通过shell命令来查询出对应的结果
mysql -e "select count(table_name) from informa