您好,登錄后才能下訂單哦!
這篇文章主要介紹“Oracle怎么連接配置數據庫”,在日常操作中,相信很多人在Oracle怎么連接配置數據庫問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Oracle怎么連接配置數據庫”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
從連接端講起。
1、連接數據庫的方式
oracle的連接串有幾部分構成,這里就按sqlplus為例,一個完成的連接串遵循下面格式
sqlplus 用戶名/密碼@主機:端口號/SID 可選as sysdba
下面先講只有listener沒有tns的情況
2、listener
使用listener連接需要配置完整連接信息,這里分為兩種連接方式,我們看一個listener的例子:
(帶sid的listener使用netmgr增加listener的datavase services即可出現sid的配置)
LISTENER2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = iZbp1d4tisi44j6vxze02fZ)(PORT = 1522))
)
SID_LIST_LISTENER2 =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = gdn1400)
(ORACLE_HOME = /fdisk1/oracle1400/base/dbhome_1)
(SID_NAME = orcl1400)
)
)
ADR_BASE_LISTENER2 = /fdisk1/oracle1400/base
LISTENER1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = iZbp1d4tisi44j6vxze02fZ)(PORT = 1521))
)
ADR_BASE_LISTENER1 = /fdisk1/oracle1400/base
這里有兩個listener,有sid的叫做靜態listener,沒有sid的叫做動態listener。在查看狀態時存在區別:
lsnrctl status listener1
...
Services Summary...
Service "orcl1400" has 1 instance(s).
Instance "orcl1400", status READY, has 1 handler(s) for this service...
Service "orcl1400XDB" has 1 instance(s).
Instance "orcl1400", status READY, has 1 handler(s) for this service...
The command completed successfully
lsnrctl status listener2
...
Services Summary...
Service "gdn1400" has 1 instance(s).
Instance "orcl1400", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
注意對于lsnrctl來說,service的名字是global database name
我們在看一個連接串:
sqlplus sys/password@iZbp1d4tisi44j6vxze02fZ:1521/orcl1400 as sysdba
這個連接串中最需要關注的就是服務名了,這里是orcl1400。
注意!:這個服務名必須由listener中的某一個提供,這里listener2的服務名提供的是gdn1400,而listener1沒有提供服務名。那么如何連接數據庫呢?答案就是走listener1的連接會去數據庫中動態的查詢服務名(所以叫做動態連接)
SQL> show parameter service
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string orcl1400
也就是為什么使用orcl1400能連上數據庫。這里我們使用靜態連接試一下,也是可以連接數據庫的(注意端口號和動態的不同)
sqlplus sys/password@iZbp1d4tisi44j6vxze02fZ:1522/gdn1400 as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu May 30 20:51:00 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>
3、TNS
那么tns是什么呢?我們看下這個連接串。
sqlplus sys/password@iZbp1d4tisi44j6vxze02fZ:1521/orcl1400 as sysdba
@后面的信息很多,能否省略呢?比如
sqlplus sys/password@tns1400 as sysdba
這樣看起來簡潔很多也便于管理,TNS即實現了這個功能,我們看一個tnsnames.ora的配置:
NSN1522 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = iZbp1d4tisi44j6vxze02fZ)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = gdn1400)
)
)
NSN1521 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = iZbp1d4tisi44j6vxze02fZ)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl1400)
)
)
這里可以看到,最左面的NSN1522和NSN1521就是我們可以@的服務名字。內部的映射信息是指向listener的,這里的servicename要和上面的global database name對應上!
NSN1522, iZbp1d4tisi44j6vxze02fZ, 1522, gdn1400 -----> listener2
NSN1521, iZbp1d4tisi44j6vxze02fZ, 1521, orcl1400 -----> listener1
兩個別名指向了兩個不同的listener,連接測試:
# sqlplus sys/password@nsn1521 as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu May 30 20:58:51 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>
# sqlplus sys/password@nsn1522 as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu May 30 20:58:55 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>
注意:tns依賴lsnrctl使用,可以理解為hostname這樣的概念,注意tns的SERVICE_NAME等信息必須和listener關聯才能連接!
到此,關于“Oracle怎么連接配置數據庫”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。