美文网首页
information_schema这个MySQL自带的库

information_schema这个MySQL自带的库

作者: 蔺蔺蔺赫赫 | 来源:发表于2019-07-19 15:25 被阅读0次

    information_schema 这是一个MySQL自带的库(虚拟库) 属于系统库 不能手动创建和删除  只要一启动 自动生成这个库 以及这里边固定好的 视图

    是不是类似于环境变量呢 只要一开机自动加载

    use information_schema;

    mysql> show tables;  里边有好多类似于表的东西

    什么是视图

        在工作中查询一个东西需要一个很大的代码量

        有没有一中方法把所有的代码操作 打进一个

        类似于文件的东西  这个类似于文件的东西就叫视图

      创建视图

      create view test as select a.mane as aname,b.name as bname,b.surfacearea

      from city as a

      left join country as b

      on a.countrycode=b.code

      where a.population<100;  

      使用视图

          select * from test;

      效果等价于select a.mane,b.name,b.surfacearea

                from city as a

                left join country as b

                on a.countrycode=b.code

                where a.population<100;

    information_schema这个MySQL自带的库 是干什么的

      先来搞清楚什么是元数据

      比如 创建一个txt文件

      除了里边的内容 还包括属性 大小 权限 归属 时间

      这些东西会单独存放在 这个文件的inode中

      这就是这个文件的元数据

      相对的对于数据库中的库 和 表 来说 除了里边的数据行之外

          也有自己的属性 大小 权限 归属 时间这些类似的东西

      还有状态 等 都属于元数据

    元数据 存放在 基表中

    -----> 基表 是无法直接查询和修改的

    -----> 只能通过 DDL对数据进行操作来修改元数据

    -----> 只能通过show ,desc,information_schema(全局累的统计和查询)来查看  无法cat

        今天仅仅通过information_schema.tables这一个视图先了解 其他的以后再说

        视图是可以通过select来查询的  但是在查询之前 应该先了解这个视图存放了什么

    查看他的业务  想查看报表的列属性一样 查看一下

    use information_schema;

    mysql> desc tables;

    | TABLE_SCHEMA    表所在的库

    | TABLE_NAME      表名

    | TABLE_TYPE      表类型

    | ENGINE          存储引擎

    | TABLE_ROWS      表的行数

    | AVG_ROW_LENGTH  行平均长度

    | INDEX_LENGTH    索引的长度

    查询整个数据库中所有的库对应的表名

    select table_schema,table_name from information_schema.tables;

    查询world库和school库对应的表名

    select table_schema,table_name

    from information_schema.tables

    where table_schema='world'

    union all

    select table_schema,table_name

    from information_schema.tables

    where table_schema='school';

    查询整个数据库中所有的库对应的表名

    select table_schema,concat(table_name)

    from information_schema.tables

        group by table_schema;

    查询整个数据库中所有的库对应的表的个数

    select table_schema,count(table_name)

    from information_schema.tables

        group by table_schema;

    查询整个数据库的真实数据量

      一张表数据量=(平均航长度*行数+索引长度)

    数据库=所有表的总和

    select SUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 as table-GB

    from information_schema.tables;

    后边的as是为了显示出来的表头为table-GB

    相关文章

      网友评论

          本文标题:information_schema这个MySQL自带的库

          本文链接:https://www.haomeiwen.com/subject/qzgdlctx.html