Linux连接oracle

2022/5/5 19:13:41

本文主要是介绍Linux连接oracle,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、下载rpm包

https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html

oracle-instantclient-basic-21.6.0.0.0-1.el8.x86_64.rpm
oracle-instantclient-sqlplus-21.6.0.0.0-1.el8.x86_64.rpm

2、安装rpm包

RedHat/CentOS直接rpm安装:

rpm -ivh oracle-instantclient-basic-21.6.0.0.0-1.el8.x86_64.rpm

rpm -ivh oracle-instantclient-sqlplus-21.6.0.0.0-1.el8.x86_64.rpm

在Debian/Ubuntu下先将其转成deb包:

alien oracle-instantclient-basic-21.6.0.0.0-1.el8.x86_64.rpm

alien oracle-instantclient-sqlplus-21.6.0.0.0-1.el8.x86_64.rpm

得到:

oracle-instantclient-basic-21.6.0.0.0-1.el8.x86_64.deb

oracle-instantclient-sqlplus-21.6.0.0.0-1.el8.x86_64.deb

然后dpkg安装:

dpkg -i oracle-instantclient-basic-21.6.0.0.0-1.el8.x86_64.deb

dpkg -i oracle-instantclient-sqlplus-21.6.0.0.0-1.el8.x86_64.deb

3、配置oracle连接

创建目录

cd /usr/lib/oracle/21/client64

mkdir network/admin

vim network/admin/tnsnames.ora

ORAL =
  (DESCRIPTION =
  (ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
  )
  (CONNECT_DATA =
  (SERVICE_NAME = oral)
  )
)

修改profile文件添加环境:

vim /etc/profile

export ORACLE_HOME=/usr/lib/oracle/21/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LD_LIBRARY_PATH=/usr/lib/oracle/21/client64/lib
export PATH=$ORACLE_HOME:$PATH

生效:

source /etc/profile

4、连接oracle

直接连接:

sqlplus username/password@远端ip:端口号/服务名

其他连接方式:

sqlplus /nolog

conn user/password@//ip:port/database

 



这篇关于Linux连接oracle的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程