MySQL 获取表字段相关信息

    xiaoxiao2021-04-19  89

    有2种方法可以获取MySQL表的字段相关信息,包括字段类型、长度、注释、主键(外键)等。

    1、使用命令 show full fields

    show full fields from table_tracker;

     FieldTypeCollationNullKeyDefaultExtraPrivilegesComment idvarchar(255)utf8_general_ciNOPRI  select,insert,update,referencesTRACKER服务ID groupidvarchar(255)utf8_general_ciYESMUL  select,insert,update,references文件系统组ID ipvarchar(80)utf8_general_ciYES   select,insert,update,referencesIP地址 portvarchar(8)utf8_general_ciYES   select,insert,update,references端口号 base_pathvarchar(512)utf8_general_ciYES   select,insert,update,references工作路径 config_pathvarchar(512)utf8_general_ciYES   select,insert,update,references配置文件

    2、使用information_schema.columns表,查询相关信息

    use information_schema; select t.column_comment,t.column_name,t.data_type,t.character_maximum_length,t.column_key  from information_schema.columns t where TABLE_SCHEMA='fastdfs' and TABLE_NAME= table_tracker';

     column_commentcolumn_namedata_typecharacter_maximum_lengthcolumn_key TRACKER服务IDidvarchar255PRI 文件系统组IDgroupidvarchar255MUL IP地址ipvarchar80  端口号portvarchar8  工作路径base_pathvarchar512  配置文件config_pathvarchar512 

    转载请注明原文地址: https://ju.6miu.com/read-675958.html

    最新回复(0)