进入数据库:
1 mysql> use sunshine_blog;
输出: 2 Database changed
查数据库表:
1 mysql> show tables;
输出: 2 +-------------------------+ 3 | Tables_in_sunshine_blog | 4 +-------------------------+ 5 | test | 6 | user | 7 +-------------------------+ 8 2 rows in set (0.00 sec)
建表:auto_increment自动递增;not null 非空;primary key(字段) 主键;
1 mysql> create table test( 2 -> name varchar(15), 3 -> email varchar(25), 4 -> phone_number int, 5 -> id int not null auto_increment, 6 -> primary key(id));
输出: 7 Query OK, 0 rows affected (0.16 sec)
显示字段、字段信息命令:
1 mysql> show columns from test;
输出: 2 +--------------+-------------+------+-----+---------+----------------+ 3 | Field | Type | Null | Key | Default | Extra | 4 +--------------+-------------+------+-----+---------+----------------+ 5 | name | varchar(15) | YES | | NULL | | 6 | email | varchar(25) | YES | | NULL | | 7 | phone_number | int(11) | YES | | NULL | | 8 | id | int(11) | NO | PRI | NULL | auto_increment | 9 +--------------+-------------+------+-----+---------+----------------+ 10 4 rows in set (0.01 sec)
与该作用相同的语句:
1 mysql> describe test;
输出: 2 +--------------+-------------+------+-----+---------+----------------+ 3 | Field | Type | Null | Key | Default | Extra | 4 +--------------+-------------+------+-----+---------+----------------+ 5 | name | varchar(15) | YES | | NULL | | 6 | email | varchar(25) | YES | | NULL | | 7 | phone_number | int(11) | YES | | NULL | | 8 | id | int(11) | NO | PRI | NULL | auto_increment | 9 +--------------+-------------+------+-----+---------+----------------+ 10 4 rows in set (0.01 sec)