mysql 建表、查表、查表结构

时间:2024-09-01 15:03:38

进入数据库:

 mysql> use sunshine_blog;
输出:
Database changed

查数据库表:

 mysql> show tables;
输出:
+-------------------------+
| Tables_in_sunshine_blog |
+-------------------------+
| test |
| user |
+-------------------------+
2 rows in set (0.00 sec)

建表:auto_increment自动递增;not null 非空;primary key(字段) 主键;

 mysql> create table test(
-> name varchar(15),
-> email varchar(25),
-> phone_number int,
-> id int not null auto_increment,
-> primary key(id));
输出:
Query OK, 0 rows affected (0.16 sec)

显示字段、字段信息命令:

 mysql> show columns from test;
输出:
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| name | varchar(15) | YES | | NULL | |
| email | varchar(25) | YES | | NULL | |
| phone_number | int(11) | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | auto_increment |
+--------------+-------------+------+-----+---------+----------------+
4 rows in set (0.01 sec) 与该作用相同的语句:
 mysql> describe test;
输出:
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| name | varchar(15) | YES | | NULL | |
| email | varchar(25) | YES | | NULL | |
| phone_number | int(11) | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | auto_increment |
+--------------+-------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)