码迷,mamicode.com
首页 > 数据库 > 详细

【mysql元数据库】使用information_schema.tables查询数据库和数据表信息

时间:2016-12-14 14:03:28      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:ble   sys   show   记录   www   name   com   rgb   dex   

技术分享

概述

对于mysql和Infobright等数据库,information_schema数据库中的表都是只读的,不能进行更新、删除和插入等操作,也不能加触发器,因为它们实际只是一个视图,不是基本表,没有关联的文件。
information_schema.tables存储了数据表的元数据信息,下面对常用的字段进行介绍:
  • table_schema: 记录数据库名
  • table_name: 记录数据表名
  • engine : 存储引擎
  • table_rows: 关于表的粗略行估计;
  • data_length : 记录表的大小(单位字节);
  • index_length : 记录表的索引的大小
  • row_format: 可以查看数据表是否压缩过;

下面介绍几种常见的用法;

information_schema.tables信息;

  1. use information_schema;
  2. show create table tables;
技术分享
  1. desc tables;
技术分享

查询所有的数据库信息

  1. select distinct TABLE_SCHEMA from tables ;
技术分享

查询数据库和数据表信息

显示mysql数据库下面的所有表信息:(共对比使用)
  1. use mysql;
  2. show tables;
技术分享
通过information_schema.table获取数据库和数据表信息:
  1. use information_schema;
  2. select TABLE_SCHEMA ,table_name from tables where table_schema like ‘mysql‘;
技术分享

数据表大小以及索引大小

示例1:mysql.time_zone相关表
技术分享
获取time_zone相关表的大小:
  1. select (sum(DATA_LENGTH) + sum(INDEX_LENGTH)) as size from tables where table_schema=‘mysql‘ and table_name like ‘time_%‘;
技术分享

示例2: 获取指定数据库的大小;
  1. select (sum(DATA_LENGTH) + sum(INDEX_LENGTH)) as size from tables where table_schema=‘mysql‘;
技术分享

判断myisam数据表是否已压缩

  1. select distinct row_format,engine from information_schema.tables where engine=‘myisam‘;
技术分享
  • Fixed: 表示已压缩;
  • Dynamic:表示未压缩;

  1. select row_format,engine,table_name from information_schema.tables where engine=‘myisam‘;
技术分享

通过Linux指令直接获取数据库和数据表信息:

  1. mysql -uroot -pxxxx -D information_schema -e "select TABLE_SCHEMA ,table_name from tables where table_schema like ‘hsm_syslog_%‘"
技术分享
参数说明:
  • 技术分享
  • -D:表示数据库名称 技术分享
  • -e:表示需要执行的指令:技术分享































【mysql元数据库】使用information_schema.tables查询数据库和数据表信息

标签:ble   sys   show   记录   www   name   com   rgb   dex   

原文地址:http://www.cnblogs.com/ssslinppp/p/6178636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!