IO多路复用:
参考博客:http://www.cnblogs.com/wupeiqi/p/6536518.html
 
socket客户端(爬虫):
http://www.cnblogs.com/wupeiqi/articles/6229292.html
 
paramiko:
http://www.cnblogs.com/wupeiqi/articles/5095821.html
 
 
MySQL语句的测试题:
题目:http://www.cnblogs.com/wupeiqi/articles/5729934.html 
答案:http://www.cnblogs.com/wupeiqi/articles/5748496.html 
特别提醒:答案里有错误的哈。 
 
数据库相关操作:
http://www.cnblogs.com/wupeiqi/articles/5713315.html
http://www.cnblogs.com/wupeiqi/articles/5713323.html
 
http://www.cnblogs.com/wupeiqi/articles/5713330.html
 
 
alex课件: 

python 之路,Day11 - python mysql and ORM

课堂笔记:

  1. IO多路复用
  2. paramiko
  3. MySQL
    - SQL语句
    - Python操作MySQL - pymysql模块

作业:主机管理

上节回顾:
  - 线程
    - 锁
    - 池
  - 进程
    - 锁
    - 池
    - 数据共享

  - 协程
    - 对线程的分片(微线程)

  - IO多路复用

    r,w,e = select.select([socket对象,...],[],[],1)

    - 同时监听多个socket对象,是否:可读、可写、异常

今日内容:
  1. IO多路复用
    - 监听多个socket变化

    - socket服务端
IO多路复用 + socket 来实现Web服务器
a. 服务端优先运行
b. 浏览器: http://......
socket + send('协议..')
c. 获取客户端发来的url,根据URL不同响应数据
d. 断开链接
产出:
a. 浏览器发送数据:按照指定规则
b. 监听多个socket对象
c.
Web框架开发者
业务开发者
d. 模块独立化

参考博客:http://www.cnblogs.com/wupeiqi/p/6536518.html
- socket客户端(爬虫)
利用一个线程,同时发送n个请求(异步非阻塞模块)

url_list [
http://www.baidu.com,
http://www.baidu1.com,
http://www.baidu2.com,
http://www.baidu3.com,

]
a. 循环列表,为每一个URL生成Socket对象
b. 每一个socket对象,向远程发送链接请求
connect: 阻塞
c. 如果连接:
发送数据:遵循格式
d. 获取响应内容
e. 关闭

注意:可读和可写状态

参考博客:http://www.cnblogs.com/wupeiqi/articles/6229292.html

产出:
1. setblockint(False)
2. select监听其他对象: def fileno():...
3. gevent,twisted,asycio ---> 单线程并发发送Http请求

2. Paramiko
参考博客:http://www.cnblogs.com/wupeiqi/articles/5095821.html
- 是一个模块,socket,SSH
- Python代码,实现远程服务器操作

功能:
a. 使用用户名密码:
- 命令 SSHClient -> Transport
- 文件 Transport
b. 使用用户名秘钥:
- 命令 SSHClient -> Transport
- 路径,也支持字符串形式
- 文件 Transport

====> SSH帮助类 <====
c.
执行创建session # 堡垒机 Bug

产出:
- 链接远程,操作:命令,文件

3. MySQL
- 什么是MySQL
服务端:
a.socket服务端运行,监听:IP和端口
b.获取客户端发送的数据: asdfasdfasdfasdfasdfasdf
c.解析
d.去文件中做操作
客户端:
a.socket客户端:基于各种语言的客户端
b.验证
c.发送命令(学习规则SQL语句)
- 安装
服务端:
客户端:

- 基本使用:
a. 申请
用户:

授权:
用户名,数据库(文件夹),表(文件),增删改查,IP

b. 连接

mysql -u root -h c1.com -p
asdfasdf

mysql -u wupeiqi -h 192.168.12.111 -p 123

c. 规则
文件夹(数据库):
create database db1 default charset utf8;
drop database db1;

show databases;
use db1;

文件(表):

show tables;

create table tb1(
id int not null auto_increment primary key,
name char(20) null default 1,
age int not null)engine=innodb default charset utf8;

# 增
insert into tb1(name,age) values('alex',18);
# 删
delete from tb1 where id>1;
# 改
update tb1 set age=168 where id=2;
# 查
select * from tb1;

============================================================

外键:foreign key 一对多
create table deparment(
id int not null auto_increment primary key,
title char(32) null
)

create table person(
id int not null auto_increment primary key,
username char(32) null ,
age int not null,
deparment_id int not null,
constraint fk_cc foreign key (deparment_id) references deparment(id)
)

双向的外键: 多对多
create table deparment(
id int not null auto_increment primary key,
title char(32) null
)

create table host(
id int not null auto_increment primary key,
ip char(32) null,
port char(32) null
)

create table de_2_host(
id int not null auto_increment primary key,
did int not null,
hid int not null,
constraint fk_did_deparment foreign key (did) references deparment(id),
constraint fk_hid_host foreign key (hid) references host(id)
)

连表:
select * from person;

select * from person
left join deparment on person.deparment_id = deparment.id
#
1 alex 18 1 1 咨询
2 oldboy 68 3 3 基础

select id from deparment where title = "基础"

select hostid from host_deparment where deparment_id=1111

select * from host id in (1,2,3)

#######

4. pymysql
pip3 install pymysql

# 内部socket

import pymysql

# 创建连接
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='t1')
# 创建游标
cursor = conn.cursor()

username = input('请输入用户名:')
pwd = input('请输入密码:')

# 执行SQL,并返回受影响行数
#effect_row = cursor.execute("select * from userinfo where username=%s and pwd = %s", (username,pwd,))

# root or 1==1 --
# adfasdf
# sql = "select * from userinfo where username=%s and pwd = %s" %(username,pwd,)
# select * from userinfo where username=root or 1==1 -- and pwd = %s
#effect_row = cursor.execute(sql)

# 提交,不然无法保存新建或者修改的数据
conn.commit()

# 关闭游标
cursor.close()
# 关闭连接
conn.close()

作业:主机管理(pymysql操作数据,paramiko远程执行命令,线程池)

表结构:
用户类型表 # id 普通用户,管理员

用户 # id 用户名 密码 用户类型ID(FK)

主机表: # id ip,端口,用户名,pwd(siyao)

用户主机表关系表: id 用户id(FK) 主机id(FK)

功能:

- 用户登录 (用户表中做验证,id)

- 显示当前用户管理的所有主机列表()

- 选中一批机器远程执行命令:
ls

PS: 增删改查

Day10 - Python异步IO、Pymysql、paramiko、的更多相关文章

  1. Python异步IO --- 轻松管理10k+并发连接

    前言   异步操作在计算机软硬件体系中是一个普遍概念,根源在于参与协作的各实体处理速度上有明显差异.软件开发中遇到的多数情况是CPU与IO的速度不匹配,所以异步IO存在于各种编程框架中,客户端比如浏览 ...

  2. python异步IO编程(一)

    python异步IO编程(一) 基础概念 协程:python  generator与coroutine 异步IO (async IO):一种由多种语言实现的与语言无关的范例(或模型). asyncio ...

  3. python异步IO编程(二)

    python异步IO编程(二) 目录 开门见山 Async IO设计模式 事件循环 asyncio 中的其他顶层函数 开门见山 下面我们用两个简单的例子来让你对异步IO有所了解 import asyn ...

  4. Python - 异步IO\数据库\队列\缓存

    协程 协程,又称微线程,纤程.英文名Coroutine.一句话说明什么是线程:协程是一种用户态的轻量级线程,协程一定是在单线程运行的. 协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文和 ...

  5. Python异步IO

    在IO操作的过程中,当前线程被挂起,而其他需要CPU执行的代码就无法被当前线程执行了. 我们可以使用多线程或者多进程来并发执行代码,为多个用户服务. 但是,一旦线程数量过多,CPU的时间就花在线程切换 ...

  6. python -- 异步IO 协程

    python 3.4 >>> import asyncio >>> from datetime import datetime >>> @asyn ...

  7. Python异步IO之协程(一):从yield from到async的使用

    引言:协程(coroutine)是Python中一直较为难理解的知识,但其在多任务协作中体现的效率又极为的突出.众所周知,Python中执行多任务还可以通过多进程或一个进程中的多线程来执行,但两者之中 ...

  8. Python 异步IO、IO多路复用

    事件驱动模型 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  9. python 异步IO

    参考链接:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143208573 ...

随机推荐

  1. js的同步异步

    由于js没有多线程,所以处理多任务的时候,可以用异步回调来解决.js中setTimeout.setInterval.ajax(jq中可以选择同步或异步)均会开启异步.遇到异步模块,会将其推入值任务队列 ...

  2. JS的Scope

    关键字:域(scope),闭包(closure),关键字this,命名空间(namespace),函数域(function scope),全局域(global scope),词法作用域(lexical ...

  3. php 与 c++ openssl 加密通信

    $key = '1234567890123456'; $iv = '1234567890123456'; $enc = openssl_encrypt("hello wolrd!" ...

  4. ubuntu 18.04 64bit下如何安装python开发工具jupyter

    1.执行一下命令进行安装 sudo apt-get install python3-distutils wget https://bootstrap.pypa.io/get-pip.py sudo p ...

  5. CORE MVC 自定义认证

    微软的认证体系,集成了EF,和它的表结构,对于我们已有的系统,或者想高度自定义的人,该怎么办呢? 答案在: https://docs.microsoft.com/en-us/aspnet/core/s ...

  6. 从零开始玩转JMX(一)——简介和Standard MBean

    JMX的全称为Java Management Extensions. 顾名思义,是管理Java的一种扩展.这种机制可以方便的管理.监控正在运行中的Java程序.常用于管理线程,内存,日志Level,服 ...

  7. linux之磁盘配额(quota)使用方法(转)

    1.什么是quota 简单的说就是限制用户对磁盘空间的使用量. 因为Linux是多用户多任务的操作系统,许多人共用磁盘空间,为了合理的分配磁盘空间,于是就有了quota的出现. 2.quota的用途  ...

  8. Nginx下修改wordpress固定链接后导致访问文章404

    假设我的wordpress博客是的 server{}段是直接放到放到了nginx.conf  (有的人为了方便管理,都习惯在单独写个vhost/目录来存放每个网站的配置文件,这就要根据你自己的设置来添 ...

  9. Codeforces Round #365 (Div. 2) B - Mishka and trip

    http://codeforces.com/contest/703/problem/B 题意: 每个点都有一个值,每条边的权值为这两个点相乘.1~n成环.现在有k个城市,城市与其他所有点都相连,计算出 ...

  10. Git出现fatal: Unable to find remote helper for 'https'

    使用Git远程获取代码 git clone https://github.com/twlkyao/findfile.git 出现“fatal: Unable to find remote helper ...