您可以使用 information_schema.columns 通过一条语句来描述数据库中的所有表。语法如下。
select *from information_schema.columns where table_schema=’yourdatabasename’\g
这里我使用带有两个表的数据库示例。
表名称如下 -
mytableyourtable为您的数据库实现上述语法。查询如下 -
mysql> select * from information_schema.columns where table_schema = 'sample'\g
以下是描述我们数据库中两个表的输出。
*************************** 1. row ***************************table_catalog: deftable_schema: sampletable_name: mytablecolumn_name: idordinal_position: 1column_default: nullis_nullable: yesdata_type: intcharacter_maximum_length: nullcharacter_octet_length: nullnumeric_precision: 10numeric_scale: 0datetime_precision: nullcharacter_set_name: nullcollation_name: nullcolumn_type: int(11)column_key:extra:privileges: select,insert,update,referencescolumn_comment:generation_expression:srs_id: null*************************** 2. row ***************************table_catalog: deftable_schema: sampletable_name: mytablecolumn_name: nameordinal_position: 2column_default: nullis_nullable: yesdata_type: varcharcharacter_maximum_length: 100character_octet_length: 400numeric_precision: nullnumeric_scale: nulldatetime_precision: nullcharacter_set_name: utf8mb4collation_name: utf8mb4_0900_ai_cicolumn_type: varchar(100)column_key:extra:privileges: select,insert,update,referencescolumn_comment:generation_expression:srs_id: null*************************** 3. row ***************************table_catalog: deftable_schema: sampletable_name: yourtablecolumn_name: idordinal_position: 1column_default: nullis_nullable: yesdata_type: intcharacter_maximum_length: nullcharacter_octet_length: nullnumeric_precision: 10numeric_scale: 0datetime_precision: nullcharacter_set_name: nullcollation_name: nullcolumn_type: int(11)column_key:extra:privileges: select,insert,update,referencescolumn_comment:generation_expression:srs_id: null*************************** 4. row ***************************table_catalog: deftable_schema: sampletable_name: yourtablecolumn_name: yournameordinal_position: 2column_default: nullis_nullable: yesdata_type: varcharcharacter_maximum_length: 100character_octet_length: 400numeric_precision: nullnumeric_scale: nulldatetime_precision: nullcharacter_set_name: utf8mb4collation_name: utf8mb4_0900_ai_cicolumn_type: varchar(100)column_key:extra:privileges: select,insert,update,referencescolumn_comment:generation_expression:srs_id: null4 rows in set (0.00 sec)
以上就是mysql中如何通过一条语句描述数据库中的所有表?的详细内容。