oracle客户端的安装是非常简单的,关键在tns配置,我这里使用的rpm安装包,oracle本身就不是开源,那使用rpm安装时最简单的。
1.要远程使用oracle,先下载下面三个文件,注意版本最好一致。
oracle-instantclient-basic-10.2.0.4-1.i386.rpm oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm oracle-instantclient-devel-10.2.0.4-1.i386.rpm |
2.PM安装
oracle-instantclient-basic-10.2.0.4-1.i386.rpm是基本的动态库、jar包,默认安装路径是:/usr/lib/oracle/10.2.0.4/client oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm是客户端sqlplus安装包, 默认安装路径是:/usr/lib/oracle/10.2.0.4/client oracle-instantclient-devel-10.2.0.4-1.i386.rpm是api接口文件,默认安装路径是:/usr/include/oracle/10.2.0.4/client |
这里不需要修改默认路径,直接安装即可:
sudo rpm-avi oracle-instantclient-basic-10.2.0.4-1.i386.rpm sudo rpm-avi oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm sudo rpm-avi oracle-instantclient-devel-10.2.0.4-1.i386.rpm |
3.配置环境变量
vi /etc/profile export ORACLE_HOME=/usr/lib/oracle/10.2.0.4 export TNS_ADMIN=$ORACLE_HOME/network/admin export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK exportLD_LIBRARY_PATH=$ORACLE_HOME/client/lib:$LD_LIBRARY_PATH exportOCI_HEADERS_HOME=/usr/include/oracle/10.2.0.4/client export OCI_LIBS_HOME=$ORACLE_HOME/client/lib |
后面两项是为了我们的程序程序编译时使用方便,编译时直接加入选项:
-I$( OCI_HEADERS_HOME) –L$( OCI_LIBS_HOME) –l occi
4.配置监听器和网络环境
[huangxw@ubuntu admin]$ cat/usr/lib/oracle/10.2.0.4/network/admin/tnsnames.ora test_base= (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = *.*.*.*)(PORT = ****)) ) (CONNECT_DATA = (SERVICE_NAME = tt4adol) ) ) |
5.测试连接
[huangxw@ubuntu bin]$./sqlplus USERNAME/PASSWD@test_base SQL*Plus: Release 10.2.0.4.0 - Production onMon Jan 13 10:09:31 2014 Copyright (c) 1982, 2007, Oracle. All Rights Reserved. Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining andReal Application Testing options SQL> select * from USERNAME.TABLENAME where accountid = 8401428; ACCOUNTID INVTA SNDA RAINA INSB SPEN REMN ---------- ---------- ---------- -------------------- ---------- ---------- INVTC SPDC REIN ---------- ---------- ---------- 8401428 0 0 100000 0 0 0 0 0 0 |