这篇文章主要介绍“mysql查看表结构的方法有哪些”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“mysql查看表结构的方法有哪些”文章能帮助大家解决问题。
1、使用的就是desc 表名查看表结构,缺点是输出的信息还不够全面。
-- desc查看表结构,也可以使用describe,desc是descride的简写,效果相同 mysql> desc info; +-------+-----------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-----------------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(20) | YES | | NULL | | | age | int(3) | YES | | NULL | | | sex | enum('male','female') | YES | | NULL | | | phone | bigint(11) | YES | | NULL | | +-------+-----------------------+------+-----+---------+-------+ 5 rows in set (0.94 sec) mysql> describe info; +-------+-----------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-----------------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(20) | YES | | NULL | | | age | int(3) | YES | | NULL | | | sex | enum('male','female') | YES | | NULL | | | phone | bigint(11) | YES | | NULL | | +-------+-----------------------+------+-----+---------+-------+ 5 rows in set (0.08 sec)
2、使用show create table语法。除了可以看到表定义之外,还可以看到engine和charset等信息。
-- desc查看表结构,也可以使用describe,desc是descride的简写,效果相同 mysql> desc info; +-------+-----------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-----------------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(20) | YES | | NULL | | | age | int(3) | YES | | NULL | | | sex | enum('male','female') | YES | | NULL | | | phone | bigint(11) | YES | | NULL | | +-------+-----------------------+------+-----+---------+-------+ 5 rows in set (0.94 sec) mysql> describe info; +-------+-----------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-----------------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(20) | YES | | NULL | | | age | int(3) | YES | | NULL | | | sex | enum('male','female') | YES | | NULL | | | phone | bigint(11) | YES | | NULL | | +-------+-----------------------+------+-----+---------+-------+ 5 rows in set (0.08 sec)