前言 本篇文章用最简单和快速的方法介绍如何在Red Hat Enterprise Linux安装Oracle Instant Client,该方法同样适用于Windows,RHEL5/6/7,OEL,CentOS。Oracle Instant Client是官方免费授权的一种比Oracle Client还要简单的数据库管理工具,通过SQL*Plus或者其它工具比如Navicat等用于快速连接和管理Oracle数据库服务器。
Install Oracle instantclient basic and instantclient sqlplus on Linux and Windows.
更新记录 2017年08月22日 - 增加oracle instant client tnsping 2017年08月14日 - 补充ORA-24454: client host name is not set的解决方案 2017年08月10日 - 初稿
阅读原文 - https://wsgzao.github.io/post/oracle-instant-client/
扩展阅读
Oracle Instant Client Downloads - http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Oracle Instant Client Downloads
文章内容均已64位版本为例,如果客户端有特殊需求请使用32位版本兼容
Linux Oracle Instant Client推荐使用RPM方式安装,如果需要定制具体路径可以使用zip包手动配置
Windows和Linux类似但需要主要PATH环境变量的配置
实测12版本客户端可以向下兼容11版本的数据库服务器,Oracle Instant Client 12.2.0.1.0,Oracle Database 11.2.0.3.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 file://C:\Dropbox\Oracle Instant Client (2 folders, 1 files, 5.51 KB, 479.15 MB in total.) │ README.md 5.51 KB ├─Linux (2 folders, 0 files, 0 bytes, 234.26 MB in total.) │ ├─11.2.0.4.0 (0 folders, 4 files, 116.57 MB, 116.57 MB in total.) │ │ instantclient-basic-linux.x64-11.2.0.4.0.zip 57.89 MB │ │ instantclient-sqlplus-linux.x64-11.2.0.4.0.zip 814.93 KB │ │ oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm 57.09 MB │ │ oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm 808.92 KB │ └─12.2.0.1.0 (0 folders, 4 files, 117.69 MB, 117.69 MB in total.) │ instantclient-basic-linux.x64-12.2.0.1.0.zip 65.77 MB │ instantclient-sqlplus-linux.x64-12.2.0.1.0.zip 883.11 KB │ oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm 50.38 MB │ oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm 691.51 KB └─Windows (2 folders, 0 files, 0 bytes, 244.89 MB in total.) ├─11.2.0.4.0 (0 folders, 4 files, 103.01 MB, 103.01 MB in total.) │ instantclient-basic-nt-11.2.0.4.0.zip 49.09 MB │ instantclient-basic-windows.x64-11.2.0.4.0.zip 52.41 MB │ instantclient-sqlplus-nt-11.2.0.4.0.zip 739.29 KB │ instantclient-sqlplus-windows.x64-11.2.0.4.0.zip 801.93 KB └─12.2.0.1.0 (0 folders, 4 files, 141.88 MB, 141.88 MB in total.) instantclient-basic-nt-12.2.0.1.0.zip 68.55 MB instantclient-basic-windows.x64-12.2.0.1.0.zip 71.59 MB instantclient-sqlplus-nt-12.2.0.1.0.zip 849.21 KB instantclient-sqlplus-windows.x64-12.2.0.1.0.zip 937.40 KB
下载地址http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
百度网盘分流http://pan.baidu.com/s/1slhoZEH
Linux
以RPM最简方式为例
Preparation Download all the required RPM from the official site and put them on the target system. Current RPMs for 64bit are: 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
Install RPMs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 rpm -ivh 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 groupadd dba useradd -g dba oracle echo oracle:oracle | chpasswdsu - oracle vi ~/.bash_profile export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/libexport TNS_ADMIN=/usr/lib/oracle/12.2/client64/export PATH=/usr/lib/oracle/12.2/client64/bin:$PATH sqlplus system/oracle@oracapdb vim /usr/lib/oracle/12.2/client64/tnsnames.ora oracapdb = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.28.70.244)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oracapdb) ) ) sqlplus system/oracle@//172.28.70.244:1521/oracapdb /bin/bash -c "echo '127.0.1.1 ${HOSTNAME} ' >> /etc/hosts"
Windows
Windows的配置相比Linux差不多简单,注意环境变量尤其是TNS_ADMIN
Preparation 国外一篇图文并茂的文章写的也很详细,有需要可以参考下 Installing Oracle instantclient basic and instantclient sqlplus on win32http://www.dbatoolz.com/t/installing-oracle-instantclient-basic-and-instantclient-sqlplus-on-win32.html
Go to Instant Client Downloads for Microsoft Windows download page:http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html
unzip files 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 instantclient-basic-windows.x64-12.2.0.1.0.zip instantclient-sqlplus-windows.x64-12.2.0.1.0.zip 计算机右键【属性】----【高级系统设置】----【环境变量】----【系统变量】----【Path】 C:\instantclient_12_2 sqlplus system/oracle@oracapdb Variable Name: TNS_ADMIN Variable Value: C:\instantclient_12_2 C:\instantclient_12_2\tnsnames.ora oracapdb = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.28.70.244)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oracapdb) ) ) sqlplus system/oracle@//172.28.70.244:1521/oracapdb
tnsping 因为某种原因Oracle官方迟迟未在Oracle Instant Client里集成tnsping,尽管不是什么大问题但相信也会给习惯使用tnsping命令测试数据库连接的小伙伴带来困扰,我这里推荐采用的方法不是像网上一样复制拷贝Standard Oracle Client,也不是完全拎起炉灶自己编写一套tnsping,而是选择使用Bash Shell模拟tnsping
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 vim /etc/profile vim ~/bash_profile whence tnsping >/dev/null 2>&1 || tnsping () { sqlplus -L -s x/x@$1 </dev/null | grep ORA- | (grep -v ORA-01017 || echo OK) } $ tnsping db999 ORA-12154: TNS:could not resolve the connect identifier specified $ tnsping db01 OK $ tnsping db02 ORA-12541: TNS:no listener