Mysql中INFORMATION_SCHEMA虚拟库使用

虚拟库字段讲解

#查看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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值