温馨提示×

ubuntu连oracle怎么弄

小樊
52
2026-09-04 22:44:46
栏目: 云计算

在 Ubuntu 上连接 Oracle 数据库,通常有以下几种常见方式,按使用场景给你梳理一下:


一、命令行连接(最常用)

1️⃣ 使用 sqlplus(Oracle 官方客户端)

安装 Oracle Instant Client

sudo apt update
sudo apt install -y libaio1 wget unzip

下载 Instant Client(需 Oracle 账号):

  • 官网:https://www.oracle.com/database/technologies/instant-client.html
  • 选择 Linux x64

例如:

wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-basic-linux.x64-21.10.0.0.0.zip
wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-sqlplus-linux.x64-21.10.0.0.0.zip

unzip instantclient-basic-linux.x64-21.10.0.0.0.zip
unzip instantclient-sqlplus-linux.x64-21.10.0.0.0.zip

配置环境变量

export ORACLE_HOME=~/instantclient_21_10
export PATH=$ORACLE_HOME:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME

连接数据库

sqlplus 用户名/密码@IP:端口/服务名

例如:

sqlplus scott/tiger@192.168.1.100:1521/orcl

二、使用 GUI 工具(推荐)

✅ DBeaver(最省事)

sudo apt install dbeaver
  • 新建连接 → Oracle
  • 填 IP / 端口 / 服务名 / 用户名密码
  • 自动下载驱动

✅ Oracle SQL Developer

  • 官网下载 .zip
  • 需 Java 环境

三、编程语言连接

Python 示例

pip install oracledb
import oracledb

conn = oracledb.connect(
    user="scott",
    password="tiger",
    host="192.168.1.100",
    port=1521,
    service_name="orcl"
)

cur = conn.cursor()
cur.execute("SELECT SYSDATE FROM dual")
print(cur.fetchone())

四、常见问题

❌ ORA-12170 连接超时

  • 防火墙没开 1521
  • Oracle 监听未启动

❌ libaio 错误

sudo apt install libaio1

❌ 服务名不知道

SELECT value FROM v$parameter WHERE name='service_names';

五、你适合哪种?

告诉我:

  • ✅ 只是连一下看数据?
  • ✅ 写代码连?
  • ✅ 本地 Ubuntu 装 Oracle?

我可以直接给你最短路径方案

0