下载

https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm

安装

 yum install ./downloads/oracle-*  
$ tree -L 1 ./downloads                   
./downloads
├── oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
└── oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm

$ sudo yum install ./downloads/oracle-*  
已加载插件:fastestmirror, langpacks
正在检查 ./oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm: oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64
./oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm 将被安装
正在检查 ./oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm: oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64
./oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 oracle-instantclient12.2-basic.x86_64.0.12.2.0.1.0-1 将被 安装
---> 软件包 oracle-instantclient12.2-sqlplus.x86_64.0.12.2.0.1.0-1 将被 安装
--> 解决依赖关系完成

.......

总计:214 M
安装大小:214 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64      1/2 
  正在安装    : oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64    2/2 
  验证中      : oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64      1/2 
  验证中      : oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64    2/2

已安装:
  oracle-instantclient12.2-basic.x86_64 0:12.2.0.1.0-1
  oracle-instantclient12.2-sqlplus.x86_64 0:12.2.0.1.0-1 

完毕!

配置环境变量

ORACLE_HOME=/usr/lib/oracle/12.2/client64
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
source /etc/profile
$ sudo vim /etc/profile 

# 添加
ORACLE_HOME=/usr/lib/oracle/12.2/client64
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export TNS_ADMIN=$ORACLE_HOME/network/admin
$ sudo source /etc/profile

测试

$ sqlplus system/PASSWORD@ec.orac.uat:1521/ecdbuat as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 22 16:48:25 2019

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> 

sqlplus 命令历史

yum install epel-release
yum install rlwrap 
alias sqlplus='rlwrap sqlplus'
$ vim ~/.bashrc 
# 添加
alias sqlplus='rlwrap sqlplus'
$ source ~/.bashrc

配置连接 tnsnames.ora

执行如下命令 cd $ORACLE_HOME,进入相应的目录下,然后执行命令 vim tnsnames.ora,并写入如下内容:

$ mkdir -p $ORACLE_HOME/network/admin/
$ cd $ORACLE_HOME/network/admin/
$ vim tnsnames.ora

ECDBUAT=
(DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 10.20.12.123)(PORT = 1521))
  (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = ECDBUAT)
  )
)
$ sqlplus system/PASSWORD@ECDBUAT  as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sun Dec 1 23:48:12 2019

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Last Successful login time: Sun Dec 01 2019 23:46:46 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL>