有的时候,乙方为甲方做项目实施或后期维护,而甲方不希望把自己的
数据库的登录帐号告诉乙方。但是乙方在为甲方做维护的时候,
比如需要运行某些批处理脚本时,则必须要登录到数据库。
从10gR2开始,我们可以将登录所需要的用户名和密码放在客户端的wallet里,然后
可以让乙方在客户端直接运行脚本,而不需要告诉他登录数据库的用户名和密码。其配置方法如下:
1、创建wallet
[oracle@EDSIR2P2 ~]$ cd $ORACLE_BASE/admin
[oracle@EDSIR2P2 admin]$ ls
orcl
[oracle@EDSIR2P2 admin]$ mkdir wallet
[oracle@EDSIR2P2 admin]$ cd wallet
[oracle@EDSIR2P2 wallet]$ pwd
/u01/app/oracle/admin/wallet
[oracle@EDSIR2P2 wallet]$ mkstore -wrl /u01/app/oracle/admin/wallet -create
Enter password:
Enter password again:
[oracle@EDSIR2P2 wallet]$ ls
cwallet.sso ewallet.p12
2、修改tnsnames.ora
[oracle@EDSIR2P2 wallet]$ cd $ORACLE_HOME/network/admin/
[oracle@EDSIR2P2 admin]$ vi tnsnames.ora
添加如下这段内容:
ORCL_HR =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = EDSIR2P2.us.oracle.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.us.oracle.com)
)
)
测试能否连接成功:
[oracle@EDSIR2P2 admin]$ sqlplus hr/hr@orcl_hr
SQL*Plus: Release 10.1.0.4.0 - Production on Wed Oct 8 17:43:09
2008Copyright (c) 1982, 2005,
Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
说明成功
3、将连接信息添加到客户端的wallet里:
[oracle@EDSIR2P2 admin]$ mkstore -wrl /u01/app/oracle/admin/wallet -createCredential orcl_hr hr hr Enter password:
Create credential oracle.security.client.connect_string1
[oracle@EDSIR2P2 admin]$
4、配置客户端的sqlnet.ora,添加如下内容:
[oracle@EDSIR2P2 admin]$ pwd
/u01/app/oracle/product/10.2.0/db_1/network/admin
[oracle@EDSIR2P2 admin]$ vi sqlnet.ora
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /u01/app/oracle/admin/wallet)
)
)
SQLNET.WALLET_OVERRIDE=true
5、测试
[oracle@EDSIR2P2 admin]$ sqlplus /@orcl_hr
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Oct 8 17:51:38 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> show user
USER is "HR"
SQL>
[oracle@EDSIR2P2 admin]$ cd
[oracle@EDSIR2P2 ~]$ vi batch.sql
然后在batch.sql里添加如下内容:
connect /@orcl_hr
select last_name,salary from employees where employee_id=100;
exit
测试该脚本:
[oracle@EDSIR2P2 ~]$ sqlplus /nolog @batch.sql
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Oct 8 17:53:22 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected.
LAST_NAME SALARY
------------------------- ----------
King 24000
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@EDSIR2P2 ~]$