登录mysql
docker exec -it mysql /bin/bash
mysql -uroot -p密码
显示数据库
show databases;
创建数据库
create database 库名;
删除数据库
drop database 库名;
创建数据表
create table 表名(字段名称,字段类型(长度限制));
查看数据表
desc 表名;
删除数据表
drop table 表名;
显示所有数据表
show tables;
查看表的数据
select * from 表名;
给表中插入数据
insert into 表名(字段) value ();
清空表的数据
delete * from 表名;
给数据表中新增字段
alter table 表名 add 新字段 字段类型(约束条件);
修改数据表中字段
alter table 表名 change 旧字段名 新字段名 字段类型;
删除数据表中字段
alter table 表名 drop 字段名;
where语句查询
select * from 表名 where 字段=""
LIKE语句模糊查询
select 字段名 from 表名 where 字段名 LIKE "%";
给表中加入创建时间字段
alter table 表名 add column create_time datetime null default current_timestamp comment 'createTime';
给表中加入更新时间字段
alter table 表名 add column update_time datetime null default current_timestamp comment 'updateTime';
排序
升序:select * from 表名 order by create_time asc;
降序:select * from 表名 order by create_time desc;
去重
select distinct from 表名;
给某个字段去重
select distinct 字段 from 表名;
正则表达式查询
select 字段 from 表名 where 字段 regexp '^';
范围查询
select 字段 from 表名 where 字段 between 20 and 23;
空值查询
注意:IS NULL 是一个整体
IS NOT NULL 表示查询字段值不为空的记录
select 字段 from 表名 where 字段 is null;