Oracle 11g Client Configuration
First download a few compressed packages from Otn
Download the address: http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
Then depending on your platform, choose a different download, I was installed under Rhel5, so I chose the Linux x86 and downloaded the following 2 packages:
The Instantclient-basic-linux32-11.1.0.7.zip Basic package provides support for Oci,occi and JDBC-OCI applications.
Instantclient-sdk-linux32-11.1.0.7.zip additional headers and makefile files, some need to compile the template needs, such as compiling PHP oci8, and Python cx_oracle. (We use only the OCI headers that are available here)
Instantclient-sqlplus-linux32-11.1.0.7.zip optional installation, sqlplus ... Sometimes it's convenient to test and manage something.
1. Establish Oracle Users and groups:
#groupadd Oinstall
#useradd-G Oinstall Oracle
#passwd Oracle
2. Create an Oracle base directory
#mkdir –p/usr/local/oracle
#chown –R oracle:oinstall/usr/local/oracle
#chmod –R 775/usr/local/oracle
Unzip the above tar.gz or zip package and copy it into the/usr/local/oracle directory.
3. Set the Oracle_home and LD_LIBRARY_PATH environment variables, and configure the Tns_admin variable (the directory where Tnsname.ora is placed). If you use Sqlplus, set the PATH environment variable as well. Modify the. Bash_profile under the Oracle User directory to add the following statement.
Export Oracle_home=/usr/local/oracle
#export ORACLE_SID=HBDB
Export Sqlpath=/usr/local/oracle
#寻找tnsnames. Ora path
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 configuration:
MYDB =
(DESCRIPTION =
(Address_list =
(address = (PROTOCOL = TCP) (HOST = 10.0.0.5) (PORT = 1521))
)
(Connect_data =
(SID = hbdb)
(SERVER = dedicated)
)
)
5.sqlplus Connection Database:
Sqlplus user/passwd@10.0.0.5/hbdb or Sqlplus user/passwd@mydb
If it appears: Sqlplus:error while loading shared libraries:/usr/local/oracle/libnnz11.so:cannot restore segment prot after reloc : Permission denied
The simplest solution is to set the SELinux bit permissive state:
[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 June 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. Test Eams Project Database access Component Dboci (c + + encapsulation of OCI)
First, create a libclntsh.so.11.1 link:
[Oracle@localhost oracle]# ln-s libclntsh.so.11.1 libclntsh.so
#include "dboci.h"
#include <iostream>
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 <<result[i][0] <<std::endl;
}
Oci. FREEEXECSQLBUF (&result, NUM, 1);
}
Oci. Close ();
return 1;
}
SCons script:
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)
Run Result:
[Root@localhost dbconnecttest]#./dbconnect
17-jun-09
To this EAMS project database access development and deployment test passed!
Incidentally, the configuration of Oracle 11g Instant Client under Windows
1. Suppose the compressed file is extracted to the D packing directory;
2. Edit environment, add d:\instantclient_11_1 to path (note before other ORACLE directories), add system environment variable tns_admin set to D:\instantclient_11_1;oracle_ Home set to D:\instantclient_11_1; Nls_lang as ' American_america '. ZHS16GBK '
For example, on Windows 2000, click Start-> Settings-> Control Panel-> System-> advanced-> environment variables, edit path in System variables list, System environment variable tns_admin set to D : \instantclient_11_1; system environment variable oracle_home set to D:\instantclient_11_1; system environment variable Nls_lang set to American_america. Zhs16gbk
3. Edit d:\instantclient_11_1\ Tnsnames.ora File:
MYDB =
(DESCRIPTION =
(Address_list =
(address = (PROTOCOL = TCP) (HOST = 10.0.0.5) (PORT = 1521))
)
(Connect_data =
(SID = hbdb)
(SERVER = dedicated)
)
)
Where: MYDB: Case name of the database
10.0.0.5 Database server address
HBDB: SID of the database;