1.python连接oracle 使用的库为cx_Oracle,
我们先把cx_Oracle模块安装好,我主要是使用pip install cx_Oracle ,python版本是3.6. 注意如下代码中:connect('user/password@ip:port/database') 其中的user 对应数据库的用户名,password对应密码,ip对应机器地址 ,port对应端口 ,database对应数据库,大家在实际使用的时候不要照搬,注意灵活替换哦。
import cx_Oracle as co
import pandas as pd
#connect oracle database
conn=co.connect('user/password@ip:port/database')
#create sursor,remember to close the cursor when you finished using
c=conn.cursor()
#query
sql='select * from table a '
r=c.execute(sql)
#get the all rusult,when get one result you can use fetchone
result=c.fetchall()
pd_result=pd.DataFrame(result)
print(pd_result)
#release the connection
c.close()
conn.close()
2.python 连接mysql
使用的库为pymysql 先安装pymysql ,依旧使用pip安装,pip install pymysql</