【Linux】mysql语句

进入容器

注意: /bin前是通过命令docker ps查出的id

docker exec -it 22515c795c34 /bin/bash

在这里插入图片描述

查看当前库

show databases;

创建库

create database dcs1; 

删除库

drop database dcs1;

进入mysql

mysql -uroot -p123456

表结构

进入dcs1库

use dcs1;

查询该库表

show tables;

创建表

create table stu(id int(4) primary key,name varchar(20) not null,sex int(2),age int(3),class int(4));

设置主键为自增长

alter table stu change stu_id id int(12) auto_increment;

查询表结构

desc stu;

修改表名

alter table stu rename stu_new;

修改表字段

alter stu change id s_id int(20);

插入字段

在第x位插入

alter table stu add class int(3) not null first;

在x后插入

alter table stu add class int(3) not null after age;

插入多个字段

alter table stu add (Eglish int(4),Chinese int(4));

调整字段位置

alter table stu modify id int(8) first;

删除

删除字段

alter table stu drop class;

删除自增长

alter table stu drop auto_increment;

删除主键

alter table stu drop primary key;

删除基本表

drop table stu;

删除数据

删除表中数据
delete  from stu;
删除指定对象
delect from stu where id=1 or id=3;
删除大量数据
truncate stu;

注:TRUNCATE,DELETE,DROP放在一起比较:
TRUNCATE TABLE:删除内容、释放空间但不删除定义。
DELETE TABLE:删除内容不删除定义,不释放空间。
DROP TABLE:删除内容和定义,释放空间。

表数据

插入数据

插入一条

insert into stu(id,age,sex,name,class)values(9,21,0,'wang',1232);

插入多条

insert into stu values(2,'hai',1,12,2132),(1,'ju',1,23,3211);

更新数据

update stu set name='wa' where id =1;
update stu set age=age+5;

查询

所有

select * from stu;

具体字段

select id,name,sex from student;

升序

select * from stu order by id desc;

降序

select * from stu order by asc;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值