首先从OTN下载几个压缩包
下载地址为: http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
然后根据你的平台,选择不同的下载,我是安装在rhel5下,所以选择了linux x86 并下载了下面2个包:
instantclient-basic-linux32-11.1.0.7.zip 基本包,提供了OCI,OCCI和JDBC-OCI应用程序的支持。
instantclient-sdk-linux32-11.1.0.7.zip 附加的头文件和makefile文件,部分需要编译的模板需要,比如编译php的oci8,和python 的cx_Oracle. (我们这里仅使用其提供的oci头文件)
instantclient-sqlplus-linux32-11.1.0.7.zip 可选安装,sqlplus..有时候测试,管理什么的很方便。
1.建立oracle用户和组:
#groupadd oinstall
#useradd -g oinstall oracle
#passwd oracle
2.建立一个Oracle 基本目录
#mkdir –p /usr/local/oracle
#chown –R oracle:oinstall /usr/local/oracle
#chmod –R 775 /usr/local/oracle
将上述tar.gz或zip包解压,拷贝到 /usr/local/oracle目录中。
3.设置 ORACLE_HOME和LD_LIBRARY_PATH环境变量,配置TNS_ADMIN变量(放置 tnsname.ora的目录).如果使用sqlplus的话,也设置下PATH环境变量。修改oracle用户目录下的 .bash_profile加入下面语句.
export ORACLE_HOME=/usr/local/oracle
#export ORACLE_SID=hbdb
export SQLPATH=/usr/local/oracle
#寻找tnsnames.ora路径
export TNS_ADMIN=/usr/local/oracle
export NLS_LANG=''american_america.ZHS16GBK''
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME
4.tnsnames.ora配置:
MYDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.5)(PORT = 1521))
)
(CONNECT_DATA =
(SID = HBDB)
(SERVER = DEDICATED)
)
)
5.sqlplus连接数据库:
sqlplus user/passwd@10.0.0.5/hbdb或sqlplus user/passwd@MYDB
如果出现:sqlplus: error while loading shared libraries: /usr/local/oracle/libnnz11.so: cannot restore segment prot after reloc: Permission denied
最简单的解决方法莫过于将SElinux设置位PERMISSIVE状态:
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[oracle@localhost ~]# sqlplus xfdb/xfdb@MYDB
SQL*Plus: Release 11.1.0.7.0 - Production on Wed Jun 17 16:37:06 2009
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select sysdate from dual;
SYSDATE
------------
17-JUN-09
SQL>
6.测试eams项目数据库访问组件dboci(对oci的c++封装)
先建立一个libclntsh.so.11.1的链接:
[oracle@localhost oracle]# ln -s libclntsh.so.11.1 libclntsh.so
#include "dboci.h"
#include
int main(void)
{
CDbOci oci;
int iret = oci.Open("xfdb", "xfdb", "HBDB");
if (iret < 1)
return 0; //
char*** result = NULL;
int num = oci.Query("select sysdate from dual", &result, 1);
if (num > 0)
{
for (int i=0; i < num; i++)
{
std::cout “高级”->“环境变量”,编辑系统变量列表中的PATH,系统环境变量TNS_ADMIN设置为d:instantclient_11_1;系统环境变量ORACLE_HOME设置为d:instantclient_11_1;系统环境变量NLS_LANG设置为american_america.ZHS16GBK
3.编辑d:instantclient_11_1 tnsnames.ora文件:
MYDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.5)(PORT = 1521))
)
(CONNECT_DATA =
(SID = HBDB)
(SERVER = DEDICATED)
)
)
其中:MYDB:数据库的事例名
10.0.0.5数据库服务器地址
HBDB:数据库的SID;