1. 创建表

创建表时,需要指定表名、字段名、字段的数据类型等信息。如

  1. create table if not exists `demo`.`first_table`(
  2. id int unsigned auto_increment primary key,
  3. first_name varchar(20),
  4. last_name varchar(20),
  5. country varchar(20)
  6. ) engine=InnoDB;

常用的数据类型如下:

  1. 数字:tinyint , smallint , mediumint , int , bigint , bit;
  2. 浮点数:decimal , float , double;
  3. 字符串:char , varchar , binary , varbinary , blob , text , enum , set;
  4. Spatial 类型;
  5. Json数据类型(mysql8.0新增);

    2. 列出所有表

    show tables;
    

    3. 查看表结构

    desc 表名

desc first_table;

image.png

4. 查看建表语句

show create table 表名

show create table first_table;

image.png

5. 克隆表结构

create table 新表名 like 就表名

create table second_table like first_table;

验证一下
image.png