First download several compressed packages from OTN
For: http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
Then select different downloads based on your platform. I installed them in rhel5, so I chose linux x86 and downloaded the following two 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 appended header files and makefile files, part of the template needs to be compiled, such as compiling php oci8, and python cx_Oracle. (Here we only use its provided oci header files)
Instantclient-sqlplus-linux32-11.1.0.7.zip optional installation, sqlplus... sometimes testing, managing what is very convenient.
1. Create oracle users and groups:
# Groupadd oinstall
# Useradd-g oinstall oracle
# Passwd oracle
2. Create an Oracle basic directory
# Mkdir-p/usr/local/oracle
# Chown-R oracle: oinstall/usr/local/oracle
# Chmod-R 775/usr/local/oracle
Decompress the tar.gz or zip package and copy it to the/usr/local/oracle directory.
3. Set the ORACLE_HOME and LD_LIBRARY_PATH environment variables, and configure the TNS_ADMIN variable (directory where tnsname. ora is placed). If sqlplus is used, set the PATH environment variable. Modify. bash_profile in the oracle user directory and add the following statement.
Export ORACLE_HOME =/usr/local/oracle
# Export ORACLE_SID = hbdb
Export SQLPATH =/usr/local/oracle
# Search for the 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. connect SQL plus to the database:
Sqlplus user/passwd@10.0.0.5/hbdb or sqlplus user/passwd @ MYDB
If: sqlplus: error while loading shared libraries:/usr/local/oracle/libnnz11.so: cannot restore segment prot after reloc: Permission denied appears
The simplest solution is to set the permissive status of the SElinux bit:
[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,200 8, Oracle. All rights reserved.
Connected:
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 the database access component dboci of the eams Project (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)
Running result:
[Root @ localhost dbconnecttest] #./dbconnect
17-JUN-09
So far, the development and deployment of database access for the eams project have passed the test!
The configuration of the oracle 11g real-time client in windows
1. Extract the compressed file to the root directory of drive D;
2. edit the environment, add d: \ instantclient_11_1 to PATH (before other Oracle Directories), add the system environment variable TNS_ADMIN to d: \ instantclient_11_1, and set ORACLE_HOME to d: \ instantclient_11_1; NLS_LANG is ''american _ america. ZHS16GBK''
For example, on Windows 2000, choose Start> Settings> Control Panel> system> advanced> environment variables ", edit the PATH in the system Variable list. Set the system environment variable TNS_ADMIN to d: \ instantclient_11_1, the system environment variable ORACLE_HOME to d: \ instantclient_11_1, and the system environment variable NLS_LANG to american_america.zhs16gb
3. Edit the 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)
)
)
Here: MYDB: database instance name
10.0.0.5 database server address
HBDB: the SID of the database;