您正在使用 IPV4 [35.173.181.0] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
[公益]保护绿色环境,构建和谐社会       悟空收录网      

【腾讯云】 爆款2核2G3M云服务器首年 61元,叠加红包再享折上折      
[公益] 地球是我家,绿化靠大家      
2024年 清明节 006
2024年 劳动节 033
2025年 元 旦 278
2025年 春 节 306
 
您现在的位置:首页 >> 数据库 >> 内容
本类新增
本类热门
Mysql查询所有表和字段信息的方法
内容摘要: 1MySQL中information_schema是什么information_schema数据库是MySQL自带的,它提供了访问数据库元数据的方式。元数据:元数据是关于数据的数据,如数据库名或表名,列的数据类型,或访问权限等。有些时候用于表述该信息的其他术语包括“数据字典”和“系统目录”。在MySQL中,把information_schema看作是一个数据......
1MySQL中information_schema是什么

information_schema数据库是MySQL自带的,它提供了访问数据库元数据的方式。

元数据:元数据是关于数据的数据,如数据库名或表名,列的数据类型,或访问权限等。有些时候用于表述该信息的其他术语包括“数据字典”和“系统目录”。

在MySQL中,把information_schema看作是一个数据库,确切说是信息数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权限等。

information_schema数据库表说明:

schemata表:提供了当前mysql实例中所有数据库的信息。是showdatabases的结果取之此表。

tables表:提供了关于数据库中的表的信息(包括视图)。详细表述了某个表属于哪个schema,表类型,表引擎,创建时间等信息。是showtablesfromschemaname的结果取之此表。

columns表:提供了表中的列信息。详细表述了某张表的所有列以及每个列的信息。是showcolumnsfromschemaname.tablename的结果取之此表。

statistics表:提供了关于表索引的信息。是showindexfromschemaname.tablename的结果取之此表。

user_privileges(用户权限表)表:给出了关于用户权限的信息。该信息源自mysql.user授权表。是非标准表。

schema_privileges(方案权限表)表:给出了关于方案(数据库)权限的信息。该信息来自mysql.db授权表。是非标准表。

table_privileges(表权限)表:给出了关于表权限的信息。该信息源自mysql.tables_priv授权表。是非标准表。

column_privileges(列权限)表:给出了关于列权限的信息。该信息源自mysql.columns_priv授权表。是非标准表。

character_sets(字符集)表:提供了mysql实例可用字符集的信息。是showcharacterset结果集取之此表。

collations表:提供了关于各字符集的对照信息。

collation_character_set_applicability表:指明了可用于校对的字符集。这些列等效于showcollation的前两个显示字段。

table_constraints表:描述了存在约束的表。以及表的约束类型。

key_column_usage表:描述了具有约束的键列。

routines表:提供了关于存储子程序(存储程序和函数)的信息。此时,routines表不包含自定义函数(UDF)。名为“mysql.procname”的列指明了对应于information_schema.routines表的mysql.proc表列。

views表:给出了关于数据库中的视图的信息。需要有showviews权限,否则无法查看视图信息。

triggers表:提供了关于触发程序的信息。必须有super权限才能查看该表。

select*frominformation_schema.schemata;

select*frominformation_schema.tables;

select*frominformation_schema.columns;

select*frominformation_schema.statistics;

select*frominformation_schema.user_privileges;

select*frominformation_schema.schema_privileges;

select*frominformation_schema.table_privileges;

select*frominformation_schema.column_privileges;

select*frominformation_schema.character_sets;

select*frominformation_schema.collations;

select*frominformation_schema.collation_character_set_applicability;

select*frominformation_schema.table_constraints;

select*frominformation_schema.key_column_usage;

select*frominformation_schema.routines;

select*frominformation_schema.views;

select*frominformation_schema.triggers;

2根据库名获取所有表的信息

【information_schema.`TABLES`】

select*frominformation_schema.tableswheretable_schema='库名';

3根据库名获取所有的字段信息

【information_schema.`COLUMNS`】

select*frominformation_schema.columns

4根据库名获取所有的表和表字段的基本信息2

selectc.table_schemaas'库名',

t.table_nameas'表名',

t.table_commentas'表注释',

c.column_nameas'列名',

c.column_commentas'列注释',

c.ordinal_positionas'列的排列顺序',

c.column_defaultas'默认值',

c.is_nullableas'是否为空',

c.data_typeas'数据类型',

c.character_maximum_lengthas'字符最大长度',

c.numeric_precisionas'数值精度(最大位数)',

c.numeric_scaleas'小数精度',

c.column_typeas列类型,

c.column_key'KEY',

c.extraas'额外说明'

frominformation_schema.tablest

leftjoininformation_schema.columnsc

ont.table_name=c.table_name

andt.table_schema=c.table_schema

wheret.table_schema='dvmdm'

orderbyc.table_name,c.ordinal_position;

5查询某个字段在多个数据库表中的分布2

selectgroup_concat(table_schemaseparator',')as'库名',

group_concat(table_nameseparator',')as'表名',

column_nameas'列名',

group_concat(column_typeseparator',')as'列类型',

group_concat(column_commentseparator',')as'注释'

frominformation_schema.columns

wheretable_schemain('库1','库2','库3')

groupbycolumn_name

orderbygroup_concat(table_schemaseparator','),column_name

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:mysql中将null值转换为0的语句

 

下一篇:MySQL页面访问统计及排名情况

发布日期:2023/4/17
手机扫二维码直达本页
发布时间:15:00:58
点  击:7
录  入:齐天大圣
相关文章
Baidu
YiJiaCMS 7.3.8 build231228(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....