1. IO multiplexing
2. Paramiko
3. Mysql-sql statement-Python operation Mysql-pymysql Module
Previous section review:
-Thread-lock-pool
-Process-lock-pool-data sharing
-coprocessor-Shard to Thread (micro-threading)-io multiplexing
R,w,e = Select.select ([socket Object,...],[],[],1)-Listen to multiple socket objects at the same time: readable, writable, exception today content:
1. IO multiplexing-Monitor multiple socket changes-socket service side IO multiplexing + sockets for Web server implementation
A. Service-side priority operation
B. Browser:/HTTP/... socket + send (' protocol. ')
c. Get the URL from the client, responding to data differently from the URL
D. Disconnecting links
Output:
A. The browser sends data: According to the specified rules
B. Listen to multiple socket objects,
C. Web Framework developer Business Developer
D. Module Independence Reference blog: Http://www.cnblogs.com/wupeiqi/p/6536518.html-socket Client (crawler) uses a thread to send n requests simultaneously (asynchronous nonblocking modules)
url_list [Http://www.baidu.com, http://www.baidu1.com, http://www.baidu2.com, http://www.baidu3.com,]
A. Looping a list, generating a socket object for each URL
B. Each socket object, send a link to a remote request connect: Blocking
C. If connection: Send data: Follow format
D. Getting response content
E. Close note: Readable and writable Status reference blog: http://www.cnblogs.com/wupeiqi/articles/6229292.html
Output:
1. Setblockint (False)
2. Select Listen to other objects: Def fileno (): ...
3. Gevent,twisted,asycio---> Single thread concurrent HTTP request
2. Paramiko Reference Blog: http://www.cnblogs.com/wupeiqi/articles/5095821.html-is a module, Socket,ssh-python code, for remote server operation
Function:
A. Using username password:-command sshclient-Transport-File Transport
B. Using the user name key:-Command sshclient-Transport-Path, also supports string form-file Transport ====> SSH helper class <====
C. Execute create session # Fortress Machine Bug
Output:
-Link remote, Action: command, File
3. mysql-what is the MySQL server:
A.socket service-side operation, monitoring: IP and Ports
B. Getting data sent by the client: ASDFASDFASDFASDFASDFASDF
C. parsing
D. Go to the file to do the operation
Client:
A.socket client: Client based in various languages
B. Verifying c. Send command (Learning rule SQL statement)-Install
Service side:
Client:-Basic use:
A. Application User: Authorization: User name, Database (folder), table (file), delete and change, IP
B. Connecting Mysql-u root-h c1.com-p asdfasdf
Mysql-u wupeiqi-h 192.168.12.111-p 123
C. Rules
Folder (database):
Create DATABASE db1 default CharSet UTF8; Drop database db1; show databases; Use DB1;
File (table):
Show tables; CREATE TABLE TB1 (ID int not NULL auto_increment primary key, name char (a) NULL default 1, age int. NOT NULL) ENGINE=INNODB Default CharSet UTF8;
# Increase
Insert into TB1 (name,age) VALUES (' Alex ', 18);
# Delete
Delete from tb1 where id>1;
# change
Update tb1 set age=168 where id=2;
#查
SELECT * from TB1;
FOREIGN key: Foreign key pair of multiple
CREATE TABLE deparment (ID int not NULL auto_increment primary key, title char (+) NULL) CREATE TABLE person (ID int. not Null Auto_increment PRIMARY key, username char (+) NULL, age int. NOT NULL, DEPARMENT_ID int. NOT NULL, constraint fk_cc fo Reign Key (deparment_id) references Deparment (ID))
Two-way foreign key:
Many-to-many CREATE TABLE deparment (ID int not NULL auto_increment primary key, title char (+) NULL) CREATE TABLE host (ID int no T null auto_increment primary key, IP char (+) NULL, port char (+) NULL) CREATE TABLE de_2_host (ID int NOT NULL AUTO_INC Rement 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))
Even table:
select * from person; SELECT * FROM person left join deparment on person.deparment_id = deparment.id
# 1 Alex 18 1 1 Consulting
2 Oldboy 68 3 3 Base
Select ID from deparment where title = "Base" Select HostID from Host_deparment where deparment_id=1111 select * from Host I D in (#######)
4. Pymysql PIP3 Install Pymysql # internal socket Import Pymysql # CREATE Connection conn = Pymysql.connect (host= ' 127.0.0.1 ', port=3306, user= ' Root ', passwd= ' 123 ', db= ' T1 ')
# Create Cursors
cursor = conn.cursor () Username = input (' Please enter user name: ') pwd = input (' Please enter password: ')
# executes SQL and returns the number of rows affected
#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)
# Commit, otherwise unable to save new or modified data conn.commit ()
# Close Cursor cursor.close () # Close connection Conn.close ()
Python operation MySQL Database