instantclient在linux下的安装配置过程
1.新建oracle用户,使用root用户
useradd oracle
passwd oracle
2.安装oracle-instantclient
yum localinstall -y oracle-instantclient12.1-basic-12.1.0.1.0-1.x86_64.rpm oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.x86_64.rpm
安装结算后,在 /usr/lib/文件夹下会出现一个新的文件夹oracle
3.修改/usr/lib/oracle文件夹的所有权
cd /usr/lib
chown -R oracle:oracle oracle
4.修改oracle用户的 .bash_profile文件,添加相应环境变量,使用oracle用户
$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=$PATH:$ORACLE_HOME/bin
5. .bash_profile文件生效
$ . ./.bash_profile
6.生成tnsnames.ora文件
$ vi /usr/lib/oracle/12.1/client64/network/admin/tnsnames.ora
CACTESTDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.109.10)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cactestdb)
)
)
7.测试
$ sqlplus /nolog
SQL*Plus: Release 12.1.0.1.0 Production on Sat Jan 4 05:27:00 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn scott/tiger@CACTESTDB
ERROR:
ORA-28000: the account is locked
SQL> conn system/manager@CACTESTDB
Connected.
SQL> select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10
14 rows selected.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
8.后记
LD_LIBRARY_PATH这个环境变量很重要,如果未设该变量的话,出错信息如下
$ sqlplus /nolog
sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory
TNS_ADMIN这个环境变量不设的话,会报下面的错误
$ sqlplus /nolog
SQL*Plus: Release 12.1.0.1.0 Production on Sat Jan 4 06:52:18 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn system/manager@cacteatdb
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified