MySQL查看表结构及查看建表语句

时间:2021-07-17 08:39:45

查看表结构:desc 表名

mysql> use recommend;
Database changed

mysql> desc user;
+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| id           | bigint(20)   | NO   | PRI | NULL    |       |
| username     | varchar(20)  | NO   |     | NULL    |       |
| password     | varchar(20)  | NO   |     | NULL    |       |
| hometown     | varchar(20)  | YES  |     | NULL    |       |
| gender       | varchar(20)  | YES  |     | NULL    |       |
| birthday     | varchar(20)  | YES  |     | NULL    |       |
| email        | varchar(20)  | YES  |     | NULL    |       |
| phone_number | varchar(20)  | YES  |     | NULL    |       |
| profession   | varchar(20)  | YES  |     | NULL    |       |
| hobby        | varchar(100) | YES  |     | NULL    |       |
+--------------+--------------+------+-----+---------+-------+
10 rows in set (0.00 sec)

查看建表语句:show create table 表名

mysql> show create table user; +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table | +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| user  | CREATE TABLE `user` (
 `id` bigint(20) NOT NULL,
 `username` varchar(20) NOT NULL,
 `password` varchar(20) NOT NULL,
 `hometown` varchar(20) DEFAULT NULL,
 `gender` varchar(20) DEFAULT NULL,
 `birthday` varchar(20) DEFAULT NULL,
 `email` varchar(20) DEFAULT NULL,
 `phone_number` varchar(20) DEFAULT NULL,
 `profession` varchar(20) DEFAULT NULL,
 `hobby` varchar(100) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 | +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

注:数据库名->recommend;表名->user