zoukankan      html  css  js  c++  java
  • MySQL中INFORMATION_SCHEMA

     

    select database();  获取当前连接的数据库name

    来源:http://www.cnblogs.com/drake-guo/p/6099436.html

    select auto_increment from information_schema.tables where table_name = "表名";
    查询了information_schema数据库下的"tables"表,里面 以 table_name  为 "表名"  的一行记录的  auto_increment字段的值

    如果我们想要查询指定表的自增ID,可以用下列语句:

    select auto_increment from tables where table_name='表名';
    当然如果有同名的数据表,查出来的可就不只是一条记录了。可以加上指定数据库的条件。
    select auto_increment from tables where table_schema='数据库名' and table_name='表名';

    直接修改指定数据表的自增ID,采用以下语句:
    update tables set auto_increment = 27 where table_schema='数据库' and table_name='表名';

    可是为什么报了如下错误呢:

    Error Code: 1044. Access denied for user 'root'@'localhost' to database 'information_schema'

    真正修改auto_increment的办法是:

    alter table 表名 auto_increment = 数字;
    原因:information_schema是只读表,不能修改!




    information_schema.tables  表的属性
    table_catalog         数据表登记目录
    table_schema          表所属的数据库名
    table_name             表名称
    table_type             表类型[system view|base  table]
    engine                 使用的数据库引擎[myisam|csv|innodb]
    version             版本,默认值10
    row_format             行格式[compact|dynamic|fixed]
    table_rows             表里所存多少行数据
    avg_row_length         平均行长度
    data_length         数据长度
    max_data_length     最大数据长度
    index_length         索引长度
    data_free             空间碎片
    auto_increment         做自增主键的自动增量当前值
    create_time         表的创建时间
    update_time         表的更新时间
    check_time             表的检查时间
    table_collation     表的字符校验编码集
    checksum             校验和
    create_options         创建选项
    table_comment         表的注释、备注
    
    
    
    information_schema 所含属性说明:
    schemata:                                    提供了当前mysql实例中所有数据库的信息。是show databases的结果取之此表。
    tables:                                        提供了关于数据库中的表的信息(包括视图)。详细表述了某个表属于哪个schema,表类型,表引擎,创建时间等信息。是show tables from schemaname的结果取之此表。
    columns:                                    提供了表中的列信息。详细表述了某张表的所有列以及每个列的信息。是show columns from schemaname.tablename的结果取之此表。
    statistics:                                    提供了关于表索引的信息。是show index from schemaname.tablename的结果取之此表。
    user_privileges(用户权限):                    给出了关于全程权限的信息。该信息源自mysql.user授权表。是非标准表。
    schema_privileges(方案权限):                给出了关于方案(数据库)权限的信息。该信息来自mysql.db授权表。是非标准表。
    table_privileges(表权限):                    给出了关于表权限的信息。该信息源自mysql.tables_priv授权表。是非标准表。
    column_privileges(列权限):                    给出了关于列权限的信息。该信息源自mysql.columns_priv授权表。是非标准表。
    character_sets(字符集):                    提供了mysql实例可用字符集的信息。是show character set结果集取之此表。
    collations:                                    提供了关于各字符集的对照信息。
    collation_character_set_applicability:        指明了可用于校对的字符集。这些列等效于show collation的前两个显示字段。
    table_constraints:                            描述了存在约束的表。以及表的约束类型。
    key_column_usage:                            描述了具有约束的键列。
    routines:                                    提供了关于存储子程序(存储程序和函数)的信息。此时,routines表不包含自定义函数(udf)。名为“mysql.proc name”的列指明了对应于information_schema.routines表的mysql.proc表列。
    views:                                        给出了关于数据库中的视图的信息。需要有show views权限,否则无法查看视图信息。
    triggers:                                    提供了关于触发程序的信息。必须有super权限才能查看该表
    
    
    
    

    information_schema.columns 属性:

    table_catalog   nvarchar(128)            表限定符。
    table_schema    nvarchar(128)            表所有者。
    table_name  nvarchar(128)                表名。
    column_name nvarchar(128)                列名。
    ordinal_position     smallint            列标识号。
    column_default  nvarchar(4000)            列的默认值。
    is_nullable varchar(3)                    列的为空性。如果列允许 null,那么该列返回 yes。否则,返回 no。
    data_type   nvarchar(128)                系统提供的数据类型。
    character_maximum_length     smallint    以字符为单位的最大长度,适于二进制数据、字符数据,或者文本和图像数据。否则,返回 null。有关更多信息,请参见数据类型。
    character_octet_length   smallint        以字节为单位的最大长度,适于二进制数据、字符数据,或者文本和图像数据。否则,返回 null。
    numeric_precision   tinyint             近似数字数据、精确数字数据、整型数据或货币数据的精度。否则,返回 null。
    numeric_precision_radix  smallint        近似数字数据、精确数字数据、整型数据或货币数据的精度基数。否则,返回 null。
    numeric_scale   tinyint                 近似数字数据、精确数字数据、整数数据或货币数据的小数位数。否则,返回 null。
    datetime_precision   smallint            datetime 及 sql-92 interval 数据类型的子类型代码。对于其它数据类型,返回 null。
    character_set_catalog   varchar(6)        如果列是字符数据或 text 数据类型,那么返回 master,指明字符集所在的数据库。否则,返回 null。
    character_set_schema    varchar(3)        如果列是字符数据或 text 数据类型,那么返回 dbo,指明字符集的所有者名称。否则,返回 null。
    character_set_name  nvarchar(128)        如果该列是字符数据或 text 数据类型,那么为字符集返回唯一的名称。否则,返回 null。
    collation_catalog   varchar(6)            如果列是字符数据或 text 数据类型,那么返回 master,指明在其中定义排序次序的数据库。否则此列为 null。
    collation_schema    varchar(3)            返回 dbo,为字符数据或 text 数据类型指明排序次序的所有者。否则,返回 null。
    collation_name  nvarchar(128)            如果列是字符数据或 text 数据类型,那么为排序次序返回唯一的名称。否则,返回 null。
    domain_catalog  nvarchar(128)            如果列是一种用户定义数据类型,那么该列是某个数据库名称,在该数据库名中创建了这种用户定义数据类型。否则,返回 null。
    domain_schema   nvarchar(128)            如果列是一种用户定义数据类型,那么该列是这种用户定义数据类型的创建者。否则,返回 null。
    domain_name nvarchar(128)                如果列是一种用户定义数据类型,那么该列是这种用户定义数据类型的名称。否则,返回 null
     
    
    
  • 相关阅读:
    Python之美[从菜鸟到高手]--Python垃圾回收机制及gc模块详解
    linux-memory-buffer-vs-cache
    MYSQL----myownstars(102)
    win10系统调用架构分析
    on io scheduling again
    Java并发编程
    elixir-lang
    mydumper工作原理, seconds_behind_master的陷阱和pt-heartbeat (102)
    深入理解JavaScript系列+ 深入理解javascript之执行上下文
    我们应该如何去了解JavaScript引擎的工作原理 系列
  • 原文地址:https://www.cnblogs.com/hahajava/p/10121016.html
Copyright © 2011-2022 走看看