学习MYSQL的第二天 day2

 

中软作业  禁止搬运!!!
*@author:辽宁生态 武新宇*/
  • linux 功能(续昨天)
  • Mysql数据库的 增删改查等指令

 

linux 功能

5.创建文件(三种方式)

1.touch xxx# touch d1
2. vim/vi xxx  [编辑文件的名命令]
# vim d2
3.echo "xxx" > d3 

 

6.vim 编辑文件+文件里面添加内容:三种模式: 命令行模式 编辑模式 尾行模式(:w保存q退出!制)

9ad057d5941e4994bcc24e30aef7cc6e.png

 

7查看文件

1.cat xxx  文件内容全部显示  少
	# cat 1.log 
	
	2.查看大文件
	more  xxx 文件内容一页一页往下翻  按 空格往下翻  q退出 ctrl+ c   ctrl+ z 
	less  xxx 文件内容一页一页往下翻  按 空格往下翻  q退出 ctrl+ c   ctrl+ z  

Mysql数据库的 常用指令

 

1 输入  命令退出 MySQL 重新登录 
输入\c不管用,可以输入强制返回
ctrl+c,敲回车就好了
quit;  强制退出

第一次安装sql注意事项:我安的是linux版本

首先reset密码否则不能创建数据库:

然后登录

2 登录账户 
mysql -uroot -p
然后输入密码
 改掉

2基础增删改查

显示数据库
show databases;
建立数据库
create database my-database
删除数据库
drop database my-database

3建表(实现不出借鉴老师笔记)

use my_database;
create TABLE mytable(
id int(11) (自动填补序号)
NOT NULL DEFAUTO_INCREMENT,(默认自增主键)、
age  int(67),
create _user varchar(20)谁建的COMMENT ‘姓名’ COMMENT注释的意思 mysql 字段注释专用 
update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,操作时间
PRIMARY KEY(id)主键:确定表唯一性
)

4插入数据:

insert into  mytable_info(name,age)VALUES("小明",20)(表名)

插入两条数据用逗号

insert into  mytable_info(name,age)VALUES("小明",20),("丽丽",20)

5查看表数据

select * from (表名)mytable;

6更改数据


9更改:update my_table set age(要改的年龄选项)where  name = '丽丽'

7删除数据

10 delete from my_table where /delete from my_table where name = '丽丽'

8其他指令

  • where

查询年龄小于18岁信息

查询年龄小于20岁的人
select * from mytable where name<20;
查询年龄18名字叫丽丽的人
select * from mytable where name = "丽丽" and age = 18;
查询年龄18 和 名字是丽丽的人
select * from mytable where name = '丽丽'or age = 18;
查询人名和英文名是丽丽的 
select * from mytable where name  in ('丽丽',"lili");
  • order by
按照年龄做升/ 降序
select * from mytable order by age asc;

select * from mytable order by age desc;
若年龄相等   按名字升序
select * from  mytable  order by age desc,name asc; 
  • like 模糊查询(regexp)
  • %模糊
  • _占位符
模糊查询
select *  from bigdata.student_info where name like "%j%";
select *  from bigdata.student_info where name like "_b%"; 
  • 合并表

union)(去除重复数据)

union all(不去除重复数据)

合并12两个表
select * form 表1名 
union 
select * form 表2名 
  • null(过滤空值/空字符串)"看情况企业一般过滤掉或者转换数值变0 "
  1. is null
  2. is 
  3. 过滤空值
    select *,ifnull(create_user,'--') as create_user_etl  from mytable;

    处理空值的函数:

聚合函数

  1. 分组:group by ... 以...进行分组
  2. 聚合函数:统计指标
select name, avg(age) as avg_age from student_info  group by name;
先分组,
A(13,67,89)
B(45,78)
再聚合avg 
A 169/3

 总结

以上就是今天内容总结,介绍了mysql常用指令的使用,学习一门软件技术或者框架时,应学会多看官方文档。

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小北..

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值