show databases;

这里以test为名称;
create database test;//注意关键字不能做名称,如果非要用关键字做名字,则要用` `

创建一个使用utf8mb4字符集的 test 数据库

如果系统没有 test 的数据库,则创建一个使用utf8mb4字符集的 test 数据库,如果有则 不创建
create database if not exists test charset utf8mb4;
use 数据库名;

drop database test;
![]()
常用数据类型: INT:整型
DECIMAL(M, D):浮点数类型
VARCHAR(SIZE):字符串类型
TIMESTAMP:日期类型
要操作数据库中的表时,需要先使用该数据库:
use test;
语法:
- CREATE TABLE table_name (
- field1 datatype,
- field2 datatype,
- field3 datatype
- );
-
案列:可以使用comment增加字段说明。

desc 表名;

show tables;

- -- 删除 stu_test 表
- drop table stu_test;
- -- 如果存在 stu_test 表,则删除 stu_test 表
- drop table if exists stu_test;
