1. 創建表
創建表時,需要指定表名、字段名、字段的數據類型等信息。如
create table if not exists `demo`.`first_table`(
id int unsigned auto_increment primary key,
first_name varchar(20),
last_name varchar(20),
country varchar(20)
) engine=InnoDB;
常用的數據類型如下:
- 數字:tinyint , smallint , mediumint , int , bigint , bit;
- 浮點數:decimal , float , double;
- 字符串:char , varchar , binary , varbinary , blob , text , enum , set;
- Spatial 類型;
- Json數據類型(mysql8.0新增);
2. 列出所有表
show tables;
3. 查看錶結構
desc 表名
desc first_table;
4. 查看建表語句
show create table 表名
show create table first_table;
5. 克隆表結構
create table 新表名 like 就表名
create table second_table like first_table;
驗證一下