在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”的错误。sql
相似地,在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程序员面试笔试宝典》,做者:小麦苗
oracle
DB宝分享的IT资料:https://mp.weixin.qq.com/s/Iwsy-zkzwgs8nYkcMz29ag
● 本文做者:小麦苗,只专一于数据库的技术,更注重技术的运用app
● 做者博客地址:http://blog.itpub.net/26736162/abstract/1/ide
● 本系列题目来源于做者的学习笔记,部分整理自网络,如有侵权或不当之处还请谅解学习
● 版权全部,欢迎分享本文,转载请保留出处
● QQ:646634621 QQ群:23016159九、618766405
● 微信:lhrbestxh
● 微信公众号:DB宝
● 提供Oracle OCP、OCM、高可用(rac+dg+ogg)和MySQL最实用的技能培训
● 题目解答如有不当之处,还望各位朋友批评指正,共同进步
长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:DB宝,学习最实用的数据库技术。
本文分享自微信公众号 - DB宝(lhrdba)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。