- 读取ORACLE数据库
- 1、安装plsql以及配置文件instanctclient
在配置文件中添加数据库ip、端口等
BZPDA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 111.111.1.111)(PORT = 1234))
)
(CONNECT_DATA =
(SERVICE_NAME = USER)
)
)
- 2、安装cx_Oracle
import cx_Oracle
conn = cx_Oracle.connect('username','password','111.111.1.1:1234/DBNAME')
import cx_Oracle
conn=cx_Oracle.connect('USERNAME','PASSWORD', '111.111.1.111:1234/DBNAME')
print('连接成功!')
cursor = conn.cursor()
sql="""
select count(*) from table_a
"""
cursor.execute(sql)
alldata = cursor.fetchall()
cursor.close()
conn.close()
2.读取mysql数据库(python3)
import pymysql
pymysql.install_as_MySQLdb()
conn = pymysql.connect(host='192.168.1.191',user='bdc',passwd='bdc',db='BZPDA') #查询world数据库