Seventh_study_summary (一)

Linux Study

Linux平台安装python3.6.4教程

  1. wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
  2. tar xf Python-3.6.4 tgz
  3. cd Python-3.6.4
  4. yum install -y zlib-devel
  5. ./configure –prefix=/usr/local/python3
    • 如果执行上面这一步时报一个关于C的错误,时由于缺少gcc的库要先安装gcc的库后再执行上面的语句,安装gcc的库:yum install -y gcc
  6. make && make install
  7. cd /etc/profile.d
  8. echo ‘export PATH=$PATH:/usr/local/python3/bin/’ > python3.sh
  9. 执行完毕后logout重新连接一下。

Linux

通用操作系统

  1. 任务:任务调度,内存分配,处理外围设备
  2. 组成:内核和系统程序(shell-人机对话的窗口, 设备驱动,底层库,服务程序等)
  3. 发展史:由linus Torvalds编写
  4. free: 自由而非免费

优点

  1. 通用的操作系统, 不跟特定的硬件绑定。
  2. 95%是C语言编写,有可移植性。
  3. 具有内核编程接口
  4. 支持多用户和多任务(后期团队一起登录,一起开发)
  5. 支持安全的分层文件系统
  6. 拥有大量的实用程序
  7. 进程间通信
  8. 强大的文档

命令按钮

登录和关机

  1. adduser student 添加用户
  2. passwd student 添加用户对应的密码
  3. shutdown 关机

文件管理

  1. ls -al  ls -l/ 查看其他目录中的文件
  2. pwd 查看自己所在的目录
  3. mkdir / rmdir 创建和删除目录 touch / rm -rf 创建和删除文件
  4. cd ../. 返回上一级 当前目录
  5. copy / move 复制 和 剪切
  6. uniq / diff / file 去重/对比/查看文档类型
  7. find 找文件夹 grep 找内容

显示文件内容

  • cat | less / more

根目录下文件

  • root / home / usr / etc / 这是最重要的几个

帮助

  • man / info / –help

下载文件

  1. wget url
  2. gzip / gunzip 压缩和解压缩
  3. tar -cvf / -xvf 压缩和解压缩
  4. xz/ xz -d 压缩和解压缩

链接

  • ln oldfile newfile  硬链接
  • ln -s oldfile newfile 软连接

包管理工具

  • yum / npm
  • install 安装
  • list 罗列
  • uptate 更新
系统命令
  1. systemctl start / stop / restart / status
  2. 防火墙80开洞   firewall-cmd –zone=public –add-port=80/tcp –permanent
  3. netstat -na | grep 3306 查看自己3306端口是否开启
  4. netstat -ntlp 查看当前哪些端口在工作
  5. systemctl enable / disable 设置开关机自动启动
  6. top 任务管理器 kill -9 进程号 杀进程
  7. chmod u+x/644 文件名 给文件加上执行的权限 u/g/o

网络命令

  1. ifconfig   ip address 查看自己ip
  2. ping -s 500 -c 3 www.baidu.com  s-单次字节  c-次数  请求3次,每次给我500字节
  3. netstat -nap  查看端口
  4. netstat -nap 2>result.txt  错误重定向
  5. netstat -nap > result.txt 2>error.txt
  6. wireshark / ethereal  数据窃听,安装此软件,并且把网卡设置为混杂模式
  7. ssh root@ip  从一个阿里云,登录到另一个阿里云
  8. sftp root@localhost
  9. Upload file 上传文件  Download file 下载文件

ping to death分布式拒绝服务攻击   –> 防D 买阿里云的服务

  • DDos = Disributed Deny of Service  ping包   ——> ping + 网站名
  • ms  延迟 发送请求开始到重新接收到信息的时间。
  • TCP flood tcp包

配置环境变量

  1. 用户登录就执行的东西,写在.bash_profile或者.bashrc中
  2. 开机就执行的程序,写在rc.local中。
  3. crond 计划任务,时间到了就执行的文件。
    • crontab -e 命令来编辑
    • 0-59 0-23 1-31 1-12 0-6 command 分钟 小时 天 月 星期 命令

vim 的使用

下载配置文件

  1. wget + 下载地址 ——下载一个vim的编辑工具,redis.
  2. .vimrc 新建一个,并在里面配置 set nu  set ts-4
  3. 可以配置一个python3

命令模式 / 底行命令模式 / 编辑模式

命令模式

  1. G / gg 文末 文首
  2. ct + f / b 翻页  
  3. 4yyp 复制
  4. u 撤销
  5. 4dd / dw 删除行 删除单词
  6. 宏 qa q 100@a
    • 命令模式下,qa 开始录制
    • 简单操作
    • q 结束录制
    • 100@a 将录制的动作执行100次。

底行命令模式

  • w! / q! 强行输入和强行退出
  • %s/x/y/g 将全文中的x 替换为y, g全局 i忽略大小写  % = (1, $)
  • set nu / nonu 设置是否有行号

编辑模式

  • 注意空格 conding:utf-8 万国码编译

nginx

  • Nginx – HTTP server 当服务器使用-静态页面。 wsgi 网关–动态页面

安装

  1. yum install nginx
  2. 将 /usr/share/local/html/index.html 换成自己的网页,就可以通过公网IP访问。
    • 阿里云和自己的防火墙上都要开放相应的端口。
    • 链接前需要开启nginx

mysql

  • RDB / Persistence / SQL – 数据持久化 能存储,能取出。保证数据正确有效,Cluster 多个服务器当跑一个任务,集群 + Load Balance(Nginx / LVS) 负载均衡 + Keepalive 热备,双活。

安装

安装

  1. yum install mariadb mariadb-server 安装客户端和服务器
  2. systemctl start mariadb 启动客户端

特点

  1. 不区分大小写
  2. not null 非空约束,不能为空
  3. varchar(20) 变长字符串,varible charactor, 最少一个字符,最多20个字符。
  4. 命名规则,见名知义,前缀
  5. 句内注释 comment ‘注释’ 句外注释 – 注释
  6. 不能用双引号,只能用单引号。
  7. 数据以表格的形式出现;
  8. 每行为记录名称;
  9. 每列记录名称所对应的数据域
  10. 列和行组成一张表单
  11. 若干的表单组成database;

连接

  1. mysql -u root -p 连接自己
  2. mysql -h id -u 用户名 -p 连接别人

使用

  1. show databases; 查看有哪些数据库
  2. create databases
  3. 字符串类型
    • char varchar tinyblob tinytext blob text很长的描述型的东西,备注
  4. create 创建表
    • not null 不为空 unique
    • into_increment 自增 一般用于主键。
  5. drop 删除表
    • drop table if exists …
  6. alter 更新表
    • alter table … add …
  7. insert into … set … 插入数据
  8. delete from … where … 删除数据
  9. updata … set .. where .. 更新数据
  10. select … from … where .. 查询
-- SQL: Structured Query Language
 --     DDL: Data Definition Language  定义    create / drop / alter
 --     DML; Data Manipulation Language  操作    insert / delete / update
 --     DQL; Data Data Query Language    查询      select
 --     DCL; Data Control Language       控制    grant / revoke

-- 创建company数据库
drop database if exists company; 
create database company default charset utf8;

-- 关系型数据库用二维表组织数据
-- 关系型数据库有自己的编程语言

-- 切换到company数据库
use company;

-- 创建部门表
-- 能够唯一确定一条记录的列,可以设置为主键
drop table if exists tb_dept; 
create table tb_dept
(
deptno integer not null comment '部门编号',
dname varchar(20) not null comment '名称',
dloc varchar(10) comment '所在地',
primary key (deptno)
);

-- 建好的表里面加一列
alter table tb_dept add ddate date comment '成立日期';

-- 向部门表添加数据
insert into tb_dept values (10, '财务部', '成都', now());
insert into tb_dept (deptno, dname) values (20, '研发部');
insert into tb_dept (deptno, dname) values (30, '销售1部'), (40, '销售2部'), (50, '后勤保障部');

-- 删除数据(注意:一定要带上条件)
delete from tb_dept where deptno=50;

-- 更新表中的部分数据
update tb_dept set dloc='深圳', ddate='2018-4-1' where deptno='30';

-- 全部查询
select * from tb_dept;
-- 投影
select deptno, dname from tb_dept;
-- 别名
select deptno as 部门编号, dname as 部门名称 from tb_dept;
-- 筛选
select deptno,dname from tb_dept where dloc='深圳';
-- 人力资源管理系统

-- 1.创建人力资源管理数据库, HR
-- 2. 切换数据库
drop database if exists HR;
create database HR default charset utf8;
use HR;

-- 3.创建部门表 TbDept, 字段有部门编号deptno, 部门名称dname, 部门所在地dloc
-- 4. 插入部门表数据
drop table if exists TbDept;
create table TbDept
(
deptno int primary key not null comment '部门编号',
dname varchar(10) not null comment '部门名称',
dloc varchar(20) not null
);


insert into TbDept values (10, '会计部', '北京');
insert into TbDept values (20, '研发部', '成都');
insert into TbDept values (30, '销售部', '重庆');
insert into TbDept values (40, '运维部', '深圳');

-- 5. 创建员工表 TbEmp, 员工编号 empno, 员工姓名ename, 员工职位job,
-- 主管编号mgr, 员工月薪sal , 所在部门编号dno.
-- 6 .插入员工表数据。
drop table if exists TbEmp;
create table TbEmp
(
empno int primary key not null comment '员工编号',
ename varchar(20),
job varchar(20),
mgr int,
sal int not null,
dno int
);
alter table TbEmp add constraint fk_dno foreign key(dno) references TbDept(deptno);

insert into tbemp values
(7800, '张三丰', '总裁', null, 9000, 20),
(2056, '乔峰', '分析师', 7800, 5000, 20),
(3088, '李莫愁', '设计师', 2056, 3500, 20),
(3211, '张无忌', '程序员', 2056, 3200, 20),
(3233, '丘处机', '程序员', 2056, 3400, 20),
(3251, '张翠山', '程序员', 2056, 4000, 20),
(5566, '宋明月', '会计师', 7800, 4000, 10),
(5234, '郭靖', '出纳', 5566, 2000, 10),
(3344, '黄蓉', '销售主管', 7800, 3000, 30),
(1359, '胡一刀', '销售员', 3344, 1800, 30),
(4466, '苗人凤', '销售员', 3344, 2500, 30),
(3244, '欧阳锋', '程序员', 3088, 3200, 20),
(3577, '杨过', '会计师', 5566, 2200, 10),
(3588, '朱九真', '会计师', 5566, 2200, 10);

-- 练习:
-- 1.查询薪水最高的员工姓名和工资
select sal, ename from tbemp
where sal = (
select max(sal)  from tbemp);
-- 2. 查询员工的姓名和年薪(月薪* 12)
select ename, sal * 12  as 年薪 from tbemp;
-- 3. 查询员工的部门的编号和人数
select count(dno)'人数',dno '部门编号',dname, from tbemp e join tbdept d on e.dno=d.deptno group by (e.dno);

select t1.deptno,t1.dname,ifnull(t2.c,0) from tbdept t1
left join
(select dno,count(*) as c from tbemp group by dno) t2
on t1.deptno = t2.dno
-- 4.查询所有部门的名称和人数
select count(dno) '人数', d.dname '部门名称' from tbemp e join tbdept d on e.dno=d.deptno group by (d.deptno);
-- 5. 查询薪水最高的员工(boss除外)的姓名和工资

select ename, sal from tbemp t1
where t1.sal = (
select max(t.sal) as maxsal from tbemp t
where t.mgr is not null) ;

-- 6. 查询薪水超过平均薪水的员工的姓名和工资
select ename '姓名', sal '工资' from tbemp where sal > (select avg(sal) from tbemp);
-- 7. 查询薪水超过其所在部门的平均薪水的员工的姓名,部门编号和工资,
-- 平均薪资,薪水大于平均薪资,关联部门,部门信息;
select e.ename '姓名', d.deptno '部门编号', e.sal '工资' from tbemp e join tbdept d on d.deptno=e.dno where sal > (select avg(sal) from tbemp where dno=10) and e.dno=10  ;
select e.ename '姓名', d.deptno '部门编号', e.sal '工资' from tbemp e join tbdept d on d.deptno=e.dno where sal > (select avg(sal) from tbemp where dno=20) and e.dno=20  ;
select e.ename '姓名', d.deptno '部门编号', e.sal '工资' from tbemp e join tbdept d on d.deptno=e.dno where sal > (select avg(sal) from tbemp where dno=30) and e.dno=30  ;

select * from tbdept t3
join(
select t1.dno, ename, sal from tbemp t1
join(
select avg(sal) as avgsal, dno from tbemp group by dno) t2
on  t1.dno = t2.dno and t1.sal > avgsal) t4
on t3.deptno = t4.dno

-- 8. 查询部门中薪水最高的人的姓名,工资和所在部门名称
select * from tbdept t3
join(
select ename,t1.dno,sal from tbemp t1
join (
select max(sal) as maxsal, dno from tbemp group by dno) t2
on t1.dno = t2.dno and maxsal=sal) as t4
on t3.deptno = t4.dno

-- 9. 查询主管的姓名和职位
select ename, job from tbemp
where empno in (
select distinct mgr from tbemp where mgr is not null)

-- 10 查询薪水排名的前三的员工姓名和工资
select sal,ename from tbemp order by (-sal) limit 3;

-- 11.求薪水排在第4-8名的员工。
select sal,ename from tbemp order by (-sal) limit 5 offset 3;
-- 1. 创建学生选课系统
-- 2. 切换数据库
drop database if exists SRS;
create database SRS default charset utf8;
use SRS;
-- 3. 创建学生表 TbStudent 主键stuid ,姓名stuname,性别stusex,生日stubirth,电话stutel,住址stuaddr,照片stuphoto(以二进制存)
drop table if exists TbStudent;
create table TbStudent(
stuid int(15) primary key not null,
stuname varchar(20) not null,
stusex int(1) default 1,
stubirth date,
stutel int(11),
stuaddr varchar(30),
stuphoto blob
);
alter table tbstudent  drop column stutel;
-- 4.创建课程表TbCourse主键cosid,班级名称cosname,学分coscredit,课程描述cosintro
drop table if exists tbcourse;
create table tbcourse
(
cosid int primary key ,
cosname varchar(20),
coscredit float,
cosintro varchar(30)
);

-- 5. 学生选课记录表TbSC 主键scid,学生外键sid ,班级外键cid,创建日期scdate, 分数score
drop table if exists tbsc;
create table tbsc
(
scid integer primary key auto_increment,
sid integer not null,
cid integer,
scdate datetime not null,
score float
);
-- 给表添加外键
alter table tbsc add constraint fk_sid foreign key (sid) references tbstudent (stuid) on delete cascade on update cascade;
alter table tbsc add constraint fk_cid foreign key (cid) references tbcourse (cosid) on delete set null on update cascade;

-- 添加学生记录
insert into tbstudent values
(1001, '张三丰', default, '1978-1-1','成都市一环路西二段17号',null);
insert into tbstudent (stuid, stuname, stubirth) values 
(1002, '郭靖', '1980-2-2');
insert into tbstudent (stuid, stuname, stusex, stubirth, stuaddr) values 
(1003, '黄蓉', 0, '1982-3-3', '成都市二环路南四段123号');
insert into tbstudent values 
(1004, '张无忌', 1, '1990-4-4', null, null),
(1005, '丘处机',1, '1983-5-5', '北京市海淀区宝盛北里西区28号',null),
(1006, '王处一',1, '1985-6-6', '深圳市宝安区宝安大道5010号',null),
(1007, '刘处玄',1, '1987-7-7', '郑州市井水去维五路21号',null),
(1008, '孙不二',0, '1989-8-8', '武汉市光谷大道61号',null),
(1009, '平一指',1, '1992-9-9', '西安市雁塔区高新六路52号',null),
(1010, '老不死',1, '1993-10-10', '广州市天河区元岗路310号',null),
(1011, '王大锤',0, '1994-11-11',null,null),
(1012, '隔壁老王',1, '1995-12-12',null,null),
(1013, '郭啸天',1, '1977-10-25', null,null);

-- 删除一条学生数据。
delete from tbstudent where stuid=1004;
update tbstudent set stubirth='1980-12-12', stuaddr='上海市宝山区同济支路199号' where stuid=1002;

-- 添加课程记录
 insert into tbcourse values 
 (1111, 'C语言设计', 3, '大神级讲师授课需要抢座'),
 (2222,'Java程序设计',3, null),
 (3333, '数据库概论', 2, null),
 (4444, '操作系统原理', 4, null);

-- 添加学生选课记录
insert into tbsc values
(default, 1001, 1111, '2016-9-1',95),
(default, 1002, 1111, '2016-9-1',94),
(default, 1001, 2222, now(),null),
(default, 1001, 3333, '2017-3-1',85),
(default, 1001, 4444, now(), null),
(default, 1002, 4444, now(), null),
(default, 1003, 2222, now(), null),
(default, 1003, 3333, now(), null),
(default, 1005, 2222, now(), null),
(default, 1006, 1111, now(), null),
(default, 1006, 2222, '2017-3-1', 80),
(default, 1006, 3333, now(), null),
(default, 1006, 4444, now(), null),
(default, 1007, 1111, '2016-9-1',null),
(default, 1007, 3333, now(), null),
(default, 1007, 4444, now(), null),
(default, 1008, 2222, now(), null),
(default, 1010, 1111, now(), null);

-- 1查询所有学生信息
select * from tbsc sc
join tbstudent st on st.stuid=sc.sid
join tbcourse co on co.cosid=sc.cid;
-- 2.查询所有课程名称及学分
select cosname, coscredit from tbcourse;
-- 3.所有女学生的姓名和出生日期(筛选)
select stuname, stubirth from tbstudent where stusex=0;
-- 4.所有80后学生的姓名 性别和出生日期(筛选)
select stuname, stusex, stubirth from tbstudent where stubirth between '1980-1-1' and '1990-1-1';
-- 5.姓王的学生姓名和性别(模糊)
select stuname, stusex from tbstudent where stuname like "王%";
-- 6.查询姓郭名字总共两个字的学生的姓名(模糊)
select stuname from tbstudent where stuname like "郭_";
-- 7. 查询姓郭名字总共三个字的学生的姓名(模糊)
select stuname from tbstudent where stuname like "郭__";
-- 8. 名字中有王字的学生的姓名(模糊)
select stuname from tbstudent where stuname like "%王%";
-- 9 没有录入家庭住址和照片的学生姓名,多条件筛选和空值处理
select stuname from tbstudent where stuaddr is null and stuphoto is null;
-- 10 学生选课的所有日期,去重
select distinct scdate from tbsc;
-- 11 学生的姓名和生日按年龄从大到小排序
select stuname, stubirth from tbstudent order by stubirth;
-- 12 所有录入了家庭住址的男学生的姓名 出生日期和家庭住址,按年龄从小到大排序,多条件筛选和排序
select stuname, stubirth, stuaddr from tbstudent where stuaddr is not null and stusex=1 order by -stubirth;
-- 13 年龄最大的学生的出生日期 聚合函数
select min(stubirth) from tbstudent ;
-- 14 年龄最小的学生的出生日期 聚合函数
select max(stubirth) from tbstudent ;
-- 15 男女学生的人数 分组和聚合函数
select count(stusex), stusex from tbstudent group by (stusex);
-- 16 课程编号为1111的课程的平均成绩, 筛选和聚合函数
select avg(score) from tbsc where cid=1111;
-- 17 学号为1001的学生所有课程的总成绩 筛选和聚合函数
select sum(score) from tbsc where sid=1001;
-- 18 每个学生的学号和平均成绩,null值处理成0,分组和聚合函数
select stuid, ifnull(sc.avg,0) from tbstudent st left join
(select avg(tbsc.score) as avg, sid from tbsc group by sid) as sc
on sc.sid=st.stuid;

-- 19 平均成绩大于等于90分的学生的学号和平均成绩
select avgscore, sid from 
(select avg(ifnull(score,0) as avg) as avgscore, sid from tbsc group by sid) where avgscore >= 90;

select stuid, ifnull(sc.avg,0) from tbstudent st left join
(select avg(tbsc.score) as avg, sid from tbsc group by sid) as sc
on sc.sid=st.stuid where sc.avg >= "90";
-- 20 年龄最大的学生的姓名
select stuname from tbstudent t1
where t1.stubirth=(
select min(t.stubirth) from tbstudent as t) ;
-- 21 选了两门以上的课程的学生的姓名
select * from tbstudent st
join (
select count(cid) as cot, sid from tbsc group by sid) sc
on sc.sid=st.stuid where sc.cot > 2;
-- 22 选课学生的姓名和平均成绩avg(score)
select stuname, avg(ifnull(score,0)) from 
tbstudent st join tbsc sc on sc.sid=st.stuid group by sid and sc.cid is not null;

select stuname, ifnull(sc.avg,0) from tbstudent st join (
select avg(score) as avg, sid from tbsc group by sid) as sc
on sc.sid=st.stuid;
-- 23 学生姓名 所选课程名称和成绩
select stuname, cosname,score from tbsc sc
join tbcourse  co on sc.cid=co.cosid
join tbstudent st on st.stuid=sc.sid;
-- 24 每个学生的姓名和选课数量。
select count(cosid), stuname from tbsc sc
join tbcourse  co on sc.cid=co.cosid
join tbstudent st on st.stuid=sc.sid 
group by sid;

redis REmote Dlctionary Server

简介

  1. 是一个有Salvatore Sanfilippo写的key-value存储系统
  2. 它时一个开源的使用ANSI C语言编写 遵守BSD协议 支持网络 可基于内存持久化的日志型 key-value数据库,并提供多张语言的API
  3. 通常被称为数据结构服务器,因为值values可以是 String Map list sets sorted sets等类型

特点

  1. 支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用
  2. 支持key-value list set zset hash等数据结构的存储
  3. 支持数据的备份,即master-slave模式的数据备份

优势

  1. 读 110000次/秒 写81000次/秒
  2. 支持二进制的Strings, Lists , Hashes, Sets, Ordered Sets
  3. 原子 – 原子性。
  4. 支持 publish / subscribe , 通知 , key 过期等特性

使用redis redis-client

  1. 启动
    • redis-server / redis-cli进入。
  2. 后台运行
    • redis-server &
  3. vim /etc/redis.conf 进入redis的配置文件
    • :/requirepass 正则查找密码,设置
  4. redis-server –help
    redis-server
  5. 访问指定IP: 端口的redis服务器
    • redis-cli -h ip -p 端口
    • 例子 redis-cli -h 172.26.77.93 -p 6379
  6. redis 五大类型; string类型 hash list set dict
    • set p 1 设置 p 的值为1
    • get p 获取p 的值
    • incr p 整数递增 ,默认值是零
    • decr p 整数递减,用在抢票的时候。

string 字符串

  • 最基本的数据类型,可以包含任何数据,一个键最大存储512MB
  • 使用 set 和 get 命令。

hash 哈希

  • 键值对集合 key => value
  • 特别适合存储对象,每个hash可以存储2^32-1
  • 使用 hmset 和 hget 命令

list 列表

  • redis列表是简单的字符串列表,按照插入顺序排列,你可以添加一个原色到列表的头部或尾部
  • 可以存储2^32-1

set 集合

  • set 是 string 类型的无序集合
  • 集合是通过哈希表实现的,所以添加, 删除,查找的复杂度都是0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值