python operation common database mysql, oracle

Description: python3 version of Oh! !

Installation pymysql

Pip Walsall pymysql

 

Quick Start

Copy the code
pymysql Import 
# Step 1: Connect to the database 
con = pymysql.connect (host = "test.lemonban.com ", # address database 
                      user = 'xxxxx', account # to log database 
                      password = "xxxxx", # Login password for the database 
                      port = 3306, # port 
                      database = 'xxxxx', # library name 
                      ) 
# step 2: create a cursor 
CUR = con.cursor () 
# the third step: the implementation of the corresponding sql statement method: the execute () 
sql = 'the FROM the SELECT * Students.;' 
cur.execute (SQL)
Copy the code

 

2、oracle

python in the butt oracle database, use third-party libraries for cx_Oracle

installation

pip install cx_Oracle

 

Quick Start

Copy the code
cx_Oracle Import                      
# first piece connects to the database parameter 'username / password / @ ip: port / library name' 
CON = cx_Oracle.connect ( 'the User / password @ Host / Databases') 
# Step create a cursor 
cur = con.cursor ()                       
# third step executed sql statement 
sql = 'the FROM the SELECT * Students.;' 
cur.execute (sql)
Copy the code

Guess you like

Origin www.cnblogs.com/xiaoduanhe/p/11457279.html