如何在客户端登录时不用提供用户名和密码

上一篇 / 下一篇  2008-10-09 08:59:01 / 个人分类:工作技术

有的时候,乙方为甲方做项目实施或后期维护,而甲方不希望把自己的数据库的登录帐号告诉乙方。但是乙方在为甲方做维护的时候,
比如需要运行某些批处理脚本时,则必须要登录到数据库。
从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 2008

Copyright (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 ~]$

TAG:

引用 删除 Guest   /   2011-05-09 22:53:03
5
vegas_lee的个人空间 引用 删除 vegas_lee   /   2009-08-28 14:55:50
5
花好月不圆的个人空间 引用 删除 花好月不圆   /   2009-06-18 17:35:34
不错
花好月不圆的个人空间 引用 删除 花好月不圆   /   2009-06-18 17:35:22
5
Dr. database 引用 删除 dcswinner   /   2009-04-03 14:02:44
5
引用 删除 Guest   /   2008-11-15 21:38:19
5
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2012-02-10  
   1234
567891011
12131415161718
19202122232425
26272829   

数据统计

  • 访问量: 53785
  • 日志数: 712
  • 建立时间: 2008-01-22
  • 更新时间: 2009-01-05

RSS订阅

Open Toolbar