首頁 >資料庫 >mysql教程 >Oracle 11g Client的配置

Oracle 11g Client的配置

WBOY
WBOY原創
2016-06-07 17:02:491120瀏覽

然后根据你的平台,选择不同的下载,我是安装在rhel5下,所以选择了linux x86 并下载了下面2个包:instantclient-basic-linux32-

首先从OTN下载几个压缩包

下载地址为:

然后根据你的平台,选择不同的下载,我是安装在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         return 0;   //
    char*** result = NULL;
    int num = oci.Query("select sysdate from dual", &result, 1);
    if (num > 0)
    {   
        for (int i=0; i         {
            std::cout         }
        oci.FreeExecSqlBuf(&result, num, 1);
    }
    oci.Close();
    return 1;
}
scons脚本:
env = Environment()
env.Append(CCFLAGS='-g')
src_files = Split('DBconnect.cpp ../dboci/source/dboci.cpp')
include = Split('/usr/local/oracle/sdk/include ../dboci/include')
lib_path = Split('/usr/local/oracle')
lib_files = Split('clntsh nnz11')
env.Program(target='dbconnect',source = src_files, LIBS=lib_files, LIBPATH=lib_path,CPPPATH=include)
运行结果:
[root@localhost dbconnecttest]# ./dbconnect
17-JUN-09
至此eams项目数据库存取的开发与部署测试通过!

顺带说明下oracle 11g即时客户端在windows下的配置

1.假设把压缩文件解压到d盘根目录;

2.编辑环境,将d:\instantclient_11_1添加到PATH中(注意位于其他Oracle目录之前),增加系统环境变量TNS_ADMIN设置为d:\instantclient_11_1;ORACLE_HOME设置为d:\instantclient_11_1;NLS_LANG为''american_america.ZHS16GBK''

例如,在Windows 2000上,依次单击“开始”->“设置”->“控制面板”->“系统”->“高级”->“环境变量”,编辑系统变量列表中的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;

linux

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn