本文來源于tSt's Blog
機(jī)房上機(jī)的時候突然想把半夜看過的Oracle知識練習(xí)一下,可惜機(jī)子上沒裝,,記得上次老師給演示的時候機(jī)子上有啊,看來只有教師機(jī)才有吧,,在管理里面看了下教師機(jī)的服務(wù),果然有Oracle,,開他的telnet,,然后執(zhí)行:
net start OracleMTSRecoveryService net start OracleOraHome92Agent net start OracleOraHome92HTTPServer net start OracleOraHome92TNSListener net start OracleServiceORACLE 教師機(jī)上的服務(wù)名和我這的是不一樣的,安裝過Oracle數(shù)據(jù)庫的朋友應(yīng)該知道的,,而且我這里開的服務(wù)多了點(diǎn),,省的要用還得開。
打開SqlPlus就準(zhǔn)備進(jìn)教師機(jī)練習(xí),,可惜總是失敗,,錯誤信息忘記了。,。,。。,。
打開cmd執(zhí)行 sqlplus /nolog 可惜怎么連接遠(yuǎn)程數(shù)據(jù)庫呢,?這命令不知道了。 問題分析: Windows下的Oracle在回應(yīng)每個客戶端的請求時,,會生成一個線程或者是進(jìn)程,,在這個線程里,它用一個隨機(jī)端口與客戶端通信,。而設(shè)置了上述參數(shù)后,,則都用統(tǒng)一的端口了(缺省是TCP1521),所以就能解決1521端口看似不能連接服務(wù)器的問題。
解決方案A:
找到系統(tǒng)菜單下的 Oracle菜單-〉Configuration and Migration Tools -〉Database Configuration Assistant,。打開界面后,,找到樹型菜單下的 oracle管理對象-〉Computers-〉<機(jī)器名>-〉Oracle主目錄下的子節(jié)點(diǎn)中,點(diǎn)擊右邊的空白處,,添加屬性,。在彈出的界面中,點(diǎn)擊添加按鈕,,添加如下屬性:
屬性名:USE_SHARED_SOCKET 屬性值:TRUE
修改后,重新啟動數(shù)據(jù)庫實(shí)例,,再使用sql plus連接,,成功! 解決方案B(針對沒有安裝Oracle的用戶):
一,、軟件下載及環(huán)境配置 1.軟件下載 到http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html下載如下三個包: instantclient-basic-win32-10.2.0.4.zip instantclient-jdbc-win32-10.2.0.4.zip instantclient-sqlplus-win32-10.2.0.4.zip將這三個包分別解壓,,然后內(nèi)容放到C:\instantclient_10_2下
然后從一臺安裝了oem的機(jī)器上復(fù)制%ORACLE_HOME\network\admin\tnsnames.ora也放到C:\instantclient_10_2中
從http://www./software/ociuldr.zip下載coiuldr.zip,解壓后里面有windows,,linux,, solaris三個版本,將ociuldr.exe 復(fù)制到C:\instantclient_10_2,,其中ociuldr.exe 是一個文本導(dǎo)出工具,,具體參數(shù)可以參考http://www./ociuldr.html介紹
2.環(huán)境變量的設(shè)置 在PATH中增加;C:\instantclient_10_2; 新建SQLPATH,,LOCAL,,TNS_ADMIN,LD_LIBRARY_PATH四個環(huán)境變量名,,變量值均為C:\instantclient_10_2,; 如果查詢結(jié)果為亂碼,設(shè)置set NLS_LANG=XXXX(例如SIMPLIFIED CHINESE_CHINA.ZHS16GBK)
3. 如果開發(fā)JAVA應(yīng)用程序,,還要配置一些環(huán)境變量, 例如CLASSPATH,JAVA_HOME等等. CLASSES12.jar 文件是 必須的,,其他的根據(jù)需要添加.
4. 如果啟動SQLPLUS時出現(xiàn)下面的錯誤: ORA-12545: Connect failed because target host or object does not exist 試著把tnsnames.ora 中的host 改成IP地址。
二,、運(yùn)行 運(yùn)行cmd c:>sqlplus /nolog SQL:>conn system/oracle@orc10g 這樣就已經(jīng)能連接遠(yuǎn)程服務(wù)器了
也可以這么連接: conn system/oracle@//192.168.1.179:1521/orc10g連接 C:\instantclient_10_2>sqlplus /nolog SQL*Plus: Release 10.2.0.4.0 - Production on Thu Nov 27 14:45:51 2008Copyright (c) 1982, 2007, Oracle. All Rights Reserved. SQL> conn system/oracle@//192.168.1.179:1521/orc10g Connected.
下面看一下ociuldr應(yīng)用的方法:
C:\instantclient_10_2>ociuldr user=system/oracle@orc10g query="select username from dba_users" file=dba_users.txt 1550 bytes allocated for column USERNAME (1) 0 rows exported at 2008-11-27 14:49:44 29 rows exported at 2008-11-27 14:49:44 output file dba_users.txt closed at 29 rows. 這樣查詢結(jié)果就輸出到dba_user.txt文件里面了,。
配置tnsnames.ora和sqlnet.ora.。如果本機(jī)找不到示例文件,,就從其他裝有oracle的機(jī)器上拷一個,。 我拷貝了10g和9i版本下各一份: 10g下tnsnames.ora內(nèi)容
# tnsnames.ora Network Configuration File: C:\oracle\product\10.1.0\Db_1\network\admin\tnsnames.ora # Generated by Oracle configuration tools.
ORC10G = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = database007)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orc10g) ) )
EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) )
10g下sqlnet.ora的內(nèi)容:
# sqlnet.ora Network Configuration File: C:\oracle\product\10.1.0\Db_1\network\admin\sqlnet.ora # Generated by Oracle configuration tools.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
9i版本下的內(nèi)容:
# TNSNAMES.ORA Network Configuration File: d:\oracle\ora92\network\admin\tnsnames.ora # Generated by Oracle configuration tools.
ORA9I_192.168.2.206 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.206)(PORT = 1521)) ) (CONNECT_DATA = (SID = ora9i) (SERVER = DEDICATED) ) )
WS_192.168.1.101 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521)) ) (CONNECT_DATA = (SID = ws) (SERVER = DEDICATED) ) )
ORA9I_192.168.2.50 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.50)(PORT = 1521)) ) (CONNECT_DATA = (SID = ora9i) (SERVER = DEDICATED) ) )
9下sqlnet.ora的內(nèi)容:
# SQLNET.ORA Network Configuration File: d:\oracle\ora92\network\admin\sqlnet.ora # Generated by Oracle configuration tools.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME) ---------------邪惡的分割線------------------ 現(xiàn)在想想當(dāng)時真笨,telnet都開了,,直接sqlplus連接不就能練了還用自己機(jī)子連接,?吃一塹長一智吧。
|