python cx-Oracle 驱动安装

安装oracle驱动

cx-Oracle驱动二进制版本下载地址
http://download.oracle.com/otn/linux/instantclient/185000/instantclient-basic-linux.x64-18.5.0.0.0dbru.zip
## 下载时需要oracle开发者帐号

说明:本次测试的操作系统为:Ubuntu-16.04,其他操作系统可以在oracle网站上查找并下载对应版本的zip包

mkdir -p /opt/oracle
cd /opt/oracle
unzip instantclient-basic-linux.x64-18.5.0.0.0dbru.zip
mv instantclient_18_5 /opt/oracle/
apt-get install libaio1 -y

配置:

echo /opt/oracle/instantclient_18_5 > /etc/ld.so.conf.d/oracle-instantclient.conf
ldconfig

echo “export LD_LIBRARY_PATH=/opt/oracle/instantclient_18_5:$LD_LIBRARY_PATH” >> /etc/profile.d/ora_env.sh

测试驱动连接

cat test_ora.py

import cx_Oracle
from sqlalchemy import create_engine

ip = 'xxx'
port = '1521'
uname = 'user'
pwd = 'pwd'
tnsname = 'xe'

dsnStr = cx_Oracle.makedsn(ip, port, service_name=tnsname)
connect_str = "oracle://%s:%s@%s" %(uname, pwd, dsnStr)
engine = create_engine(connect_str, encoding='utf-8')

conn = cx_Oracle.connect(uname, pwd, dsn=dsnStr)

if __name__ == '__main__':
    print(engine.url)
    import pandas as pd
    r = pd.read_sql('select * from v$version',con=engine)
    print(r)

驱动测试运行结果

python test_ora.py

oracle://user:pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=IP)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xe)))
                                               banner
 0  Oracle Database 11g Express Edition Release 11…
 1             PL/SQL Release 11.2.0.2.0 - Production
 2                       CORE\t11.2.0.2.0\tProduction
 3     TNS for Linux: Version 11.2.0.2.0 - Production
 4             NLSRTL Version 11.2.0.2.0 - Production

参考文档

https://cx-oracle.readthedocs.io/en/latest/installation.html#installing-cx-oracle-on-linux

https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

u2

Related Posts

mysql连接失败:The driver has not received any packets from the server

解决java spring连接mysql报错问题,增加连接串参数

Read more

Nginx 在if语句中限制IP访问

一些web服务,出于安全考虑是不想让其他人访问到,除了添加登录用户认证外,还可以使用Nginx限制IP访问,只允许指定IP的用户访问站点或者接口。

Read more

You Missed

AI很厉害,可你省的人力费还不够买Token!

  • u2
  • 6月 2, 2026
  • 33 views

RSI取代AGI成为新热词:AI能自我进化吗?

  • u2
  • 5月 30, 2026
  • 61 views

纳斯达克指数创历史新高–全球资本对科技产业未来的重新定价!

  • u2
  • 5月 29, 2026
  • 86 views

GPT-5 Pro 自证数学定理:AI 的”博士级”时刻到了吗?

  • u2
  • 5月 28, 2026
  • 67 views

那个”AI监听你手机”的谎言,终于被戳破了

  • u2
  • 5月 27, 2026
  • 57 views

AI发现漏洞的速度已超越人类修复能力——Project Glasswing开启网络安全新纪元

  • u2
  • 5月 24, 2026
  • 85 views