mySQL常用基础命令

1 篇文章 0 订阅
  1. 登录mysql

docker exec -it mysql /bin/bash
mysql -uroot -p密码
  1. 显示数据库

show databases;
  1. 创建数据库

create database 库名;
  1. 删除数据库

drop database 库名;
  1. 创建数据表

create table 表名(字段名称,字段类型(长度限制));
  1. 查看数据表

desc 表名;
  1. 删除数据表

drop table 表名;
  1. 显示所有数据表

show tables;
  1. 查看表的数据

select * from 表名;
  1. 给表中插入数据

insert into 表名(字段) value ();
  1. 清空表的数据

delete * from 表名;
  1. 给数据表中新增字段

alter table 表名 add 新字段 字段类型(约束条件);
  1. 修改数据表中字段

alter table 表名 change 旧字段名 新字段名 字段类型;
  1. 删除数据表中字段

alter table 表名 drop 字段名;
  1. where语句查询

select * from 表名 where 字段=""
  1. LIKE语句模糊查询

select 字段名 from 表名 where 字段名 LIKE "%";
  1. 给表中加入创建时间字段

alter table 表名 add column create_time datetime null default current_timestamp comment 'createTime';
  1. 给表中加入更新时间字段

alter table 表名 add column update_time datetime null default current_timestamp comment 'updateTime';
  1. 排序

升序:select * from 表名 order by create_time asc;
降序:select * from 表名 order by create_time desc;
  1. 去重

select distinct from 表名;
  1. 给某个字段去重

select distinct 字段 from 表名;
  1. 正则表达式查询

select 字段 from 表名 where 字段 regexp '^';
  1. 范围查询

select 字段 from 表名 where 字段 between 20 and 23;
  1. 空值查询

注意:IS NULL 是一个整体

IS NOT NULL 表示查询字段值不为空的记录

select 字段 from 表名 where 字段 is null;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值