在Oracle中,TWO_TASK环境变量的作用是什么?
♣ 答案
在Linux环境下,可以设置TWO_TASK环境变量,当用户连接数据库且没有指定服务名时,会自动利用TWO_TASK的设置作为环境变量连接数据库。其中,TWO_TASK的值为tnsnames.ora文件中配置的值。示例如下所示:
1[LHRDB1:oracle]:/oracle>ORACLE_SID=
2[LHRDB1:oracle]:/oracle>TWO_TASK=
3[LHRDB1:oracle]:/oracle>sqlplus lhr/lhr
4SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 31 16:17:38 2016
5Copyright (c) 1982, 2013, Oracle. All rights reserved.
6ERROR:
7ORA-12162: TNS:net service name is incorrectly specified
8[LHRDB1:oracle]:/oracle>more $ORACLE_HOME/net*/ad*/tns*
9# tnsnames.ora Network Configuration File: /oracle/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora
10# Generated by Oracle configuration tools.
11lhrdb =
12 (DESCRIPTION =
13 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.130)(PORT = 1521))
14 (CONNECT_DATA =
15 (SERVER = DEDICATED)
16 (SERVICE_NAME = lhrdb)
17 )
18 )
19[LHRDB1:oracle]:/oracle>export TWO_TASK=lhrdb
20[LHRDB1:oracle]:/oracle>sqlplus lhr/lhr
21SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 31 16:17:53 2016
22Copyright (c) 1982, 2013, Oracle. All rights reserved.
23Connected to:
24Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
25With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
26Data Mining and Real Application Testing options
27LHR@lhrdb>
28[LHRDB1:oracle]:/oracle>sqlplus / as sysdba
29SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 31 16:18:07 2016
30Copyright (c) 1982, 2013, Oracle. All rights reserved.
31ERROR:
32ORA-01017: invalid username/password; logon denied
33Enter user-name:
需要注意的是,当配置了TWO_TASK环境变量后,就无法使用操作系统验证来登录数据库了,会报“ORA-01017: invalid username/password; logon denied”的错误。
类似地,在Windows环境下的变量是LOCAL,其设置方法和Linux下的TWO_TASK一致,如下所示:
1C:\Users\lhr>sqlplus lhr/lhr
2SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 31 16:28:25 2016
3Copyright (c) 1982, 2010, Oracle. All rights reserved.
4ERROR:
5ORA-12560: TNS:protocol adapter error
6Enter user-name:
7C:\Users\lhr>more "%ORACLE_HOME%/network/admin/tnsnames.ora"
8# tnsnames.ora Network Configuration File: D:\app\oracle\product\11.2.0.1\network\admin\tnsnames.ora
9# Generated by Oracle configuration tools.
10lhrdb =
11 (DESCRIPTION =
12 (ADDRESS = (PROTOCOL = TCP)(HOST = 22.188.194.64)(PORT = 1521))
13 (CONNECT_DATA =
14 (SERVER = DEDICATED)
15 (SERVICE_NAME = lhrdb)
16 )
17 )
18C:\Users\lhr>set LOCAL=lhrdb
19C:\Users\lhr>sqlplus lhr/lhr
20SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 31 16:29:25 2016
21Copyright (c) 1982, 2010, Oracle. All rights reserved.
22Connected to:
23Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
24With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
25Data Mining and Real Application Testing options
26SQL>
& 说明:
有关TWO_TASK和LOCAL的更多内容可以参考我的BLOG:http://blog.itpub.net/26736162/viewspace-2140246/、http://blog.itpub.net/26736162/viewspace-2123414/
本文选自《Oracle程序员面试笔试宝典》,作者:小麦苗
DB宝分享的IT资料:https://mp.weixin.qq.com/s/Iwsy-zkzwgs8nYkcMz29ag
● 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用
● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/
● 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
● QQ:646634621 QQ群:230161599、618766405
● 微信:lhrbestxh
● 微信公众号:DB宝
● 提供Oracle OCP、OCM、高可用(rac+dg+ogg)和MySQL最实用的技能培训
● 题目解答若有不当之处,还望各位朋友批评指正,共同进步
长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:DB宝,学习最实用的数据库技术。
本文分享自微信公众号 - DB宝(lhrdba)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。