在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源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。