测试在centos7.2及7.4系统中使用下面百度网盘提供的11.2.0.4的64位linux客户端连接64位的oracle11gr2数据库均正常。
1、oracle官网下载并解压以下3个包到当前目录
oracle官网下载地址:根据oracle数据库版本及客户机系统选择下载对应版本
百度网盘下载:instantclient-linux.x64-11.2.0.4(密码:2zpu)
1 2 3 |
[root@imzcy ~]# unzip instantclient-basic-linux.x64-11.2.0.4.0.zip [root@imzcy ~]# unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip [root@imzcy ~]# unzip instantclient-sqlplus-linux.x64-11.2.0.4.0.zip |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[root@imzcy ~]# ll instantclient_11_2/ 总用量 186448 -rwxrwxr-x 1 root root 25420 8月 25 2013 adrci -rw-rw-r-- 1 root root 439 8月 25 2013 BASIC_README -rwxrwxr-x 1 root root 47860 8月 25 2013 genezi -r-xr-xr-x 1 root root 368 8月 25 2013 glogin.sql -rwxrwxr-x 1 root root 53865194 8月 25 2013 libclntsh.so.11.1 -r-xr-xr-x 1 root root 7996693 8月 25 2013 libnnz11.so -rwxrwxr-x 1 root root 1973074 8月 25 2013 libocci.so.11.1 -rwxrwxr-x 1 root root 118738042 8月 25 2013 libociei.so -r-xr-xr-x 1 root root 164942 8月 25 2013 libocijdbc11.so -r-xr-xr-x 1 root root 1502287 8月 25 2013 libsqlplusic.so -r-xr-xr-x 1 root root 1469542 8月 25 2013 libsqlplus.so -r--r--r-- 1 root root 2091135 8月 25 2013 ojdbc5.jar -r--r--r-- 1 root root 2739616 8月 25 2013 ojdbc6.jar drwxrwxr-x 4 root root 84 8月 25 2013 sdk -r-xr-xr-x 1 root root 9320 8月 25 2013 sqlplus -rw-rw-r-- 1 root root 443 8月 25 2013 SQLPLUS_README -rwxrwxr-x 1 root root 192365 8月 25 2013 uidrvci -rw-rw-r-- 1 root root 66779 8月 25 2013 xstreams.jar [root@imzcy ~]# |
2、创建tnsnames.ora配置文件
1 2 3 4 5 6 7 8 9 10 11 |
[root@imzcy ~]# vi instantclient_11_2/tnsnames.ora ORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.5)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = DB01) ) ) [root@imzcy ~]# |
3、创建连接数据脚本用于连接数据库,测试不使用脚本时无法直接登录数据库
3.1 创建脚本,导出oracle客户端目录,并定义连接用户(定义的变量只在执行脚本时生效,不会修改当前环境变量,起到一定的安全性)
1 2 3 4 5 6 7 8 9 10 |
[root@imzcy ~]# cat ora.sh #!/bin/bash export ORA_INSTANCE=/root/instantclient_11_2 export TNS_ADMIN=$ORA_INSTANCE export LD_LIBRARY_PATH=$ORA_INSTANCE export SQLPATH=$ORA_INSTANCE ${ORA_INSTANCE}/sqlplus sde/sde@orcl [root@imzcy ~]# |
3.2 执行脚本即可连接进数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@imzcy ~]# sh ora.sh SQL*Plus: Release 11.2.0.4.0 Production on Mon Sep 10 10:52:02 2018 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> SQL> |
3.3、测试不使用脚本时无法正常连接到数据库
1 2 3 4 5 6 7 |
[root@imzcy ~]# sqlplus bash: sqlplus: 未找到命令... [root@imzcy ~]# [root@imzcy ~]# instantclient_11_2/sqlplus sde/sde@orcl instantclient_11_2/sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory [root@imzcy ~]# |