![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnL4czM0QDMwYzMx0COzQzMwczMxEzMxkDM4EDMy0SM1IDNzQTMvwVOwgTMwIzLcFTNyQzM0EzLcd2bsJ2Lc12bj5ycn9Gbi52YugTMwIzcldWYtl2Lc9CX6MHc0RHaiojIsJye.png)
我們從上面可以看出:
需要
1.oracle client用戶端(這兒使用,oracle instance client ,簡單)
2.odbc驅動 oracle instance client預設就有
3.linux下需要安裝Linux oracle 伺服器
4.兩個配置檔案tnsnames.ora,listener.ora
tnsnames.ora ====》用戶端連接配接伺服器配置檔案
listener.ora ===》伺服器偵聽服務配置
linux oracle伺服器 listener.ora:
[[email protected] admin]$ pwd
/home/oracle_11/app/oracle/product/11.2.0/db_1/network/admin
首先安裝Linux 下的oracle,可以看這個https://www.cnblogs.com/bwbfight/p/9621218.html
安裝好後Linux 下需要做的事
1 oracle虛拟機需要固定IP,才能被外面的用戶端連接配接上來
Root登陸linux機器
系統/首選項/網絡連接配接
重新開機系統
2 oracle使用者啟動oracle伺服器
3 在linux環境中,用sqlplus工具通路oracle服務
在oracle使用者下,用sqlplus通路oracle服務
必須用scott/aa @orcl這種形成通路成功,則背景伺服器程式才能通路成功
在非oracle使用者下(比如在test03),用sqlplus通路oracle服務
必須用scott/[email protected]這種形成通路成功,則背景伺服器程式才能通路成功
chmod 777 /home/oracle_11/app -R (root使用者) 修改oracle家目錄權限
同時配置.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
umask 022
ORACLE_BASE=/home/oracle_11/app
ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/db_1
ORACLE_SID=orcl
PATH=$PATH:./:$HOME/bin:$ORACLE_HOME/bin
LD_LIBRARY_PATH=./lib:$HOME/lib:/usr/lib:$ORACLE_HOME/lib
#LANG=C
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH LD_LIBRARY_PATH
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK; export NLS_LANG
根據自己環境修改
ORACLE_BASE ORACLE_HOME ORACLE_SID PATH LD_LIBRARY_PATH
4 在win環境中,用sqlplus工具通路linux環境下的oracle服務( 192.168.43.252為linux伺服器ip)
1 Ping 192.168.43.252
2 telnet 192.168.43.252 1521 防火牆沒有把端口給封住
//防火牆 linux伺服器 1521 端口 放開
linux下: ufw disable
接着Linux開啟oracle服務并監聽:
1. 啟動oracle服務 (啟動oracle伺服器 必須使用oracle使用者)-
啟動oracle服務 (啟動oracle伺服器 必須使用oracle使用者)-
[[email protected] ~]$ sqlplus /nolog
SQL> connect /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 780824576 bytes
Fixed Size 2217424 bytes
Variable Size 599788080 bytes
Database Buffers 176160768 bytes
Redo Buffers 2658304 bytes
Database mounted.
Database opened.
2.啟動監聽伺服器
[[email protected] ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 31-JAN-2016 06:12:24
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Starting /home/oracle_11/app/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /home/oracle_11/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Log messages written to /home/oracle_11/app/diag/tnslsnr/localhost/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
注意:
ok... Linux下的事情幹完了,
接着windows下接着幹活
1. oracle instance client 安裝:https://www.oracle.com/technetwork/cn/database/features/instant-client/index-092699-zhs.html(注意是32位還是64位,不然不工作了)
2.解壓後放到固定目錄:
我的是放到e盤:E:\oracle_client\instantclient_18_3
配置
Win機器的tnsnames.ora,建立tnsnames.ora放到E:\oracle_client\instantclient_18_3下
内容如下
# tnsnames.ora Network Configuration File: E:\oracle_client\instantclient_18_3
SECMNGADEMIN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.32.253)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
HOST:伺服器IP位址
PORT:oracle端口号
SERVICE_NAME:oracle資料庫上的執行個體名稱(安裝時如果沒有指定一般為orcl)
配置windows環境變量
TNS_ADMIN =E:\oracle_client\instantclient_18_3
NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK
說明:TNS_ADMIN,是指tnsnames.ora檔案所在的目錄名。
如果指定到用戶端目錄,則必須把tnsnames.ora檔案複制過來才可以
設定ORACLE_HOME環境變量
ORACLE_HOME=E:\oracle_client\instantclient_18_3
Path後面加一個;E:\oracle_client\instantclient_18_3
在windows cmd測試
sqlplus scott/[email protected] (tiger為密碼),如果能夠執行,說明配置正确
可能會報錯
oracle的12154錯誤排查
分别在linux 下和windows下輸入:sqlplus scott/[email protected]
1 .linux 下用test03(其他使用者)不能通路oracle問題排查
2. windows下cmd通路出現如下
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
ORA-12154 11.2.0.1.0 ORA-12154
2 解決方法
[[email protected] admin]$ pwd
/home/oracle_11/app/oracle/product/11.2.0/db_1/network/admin
[[email protected] admin]$ ls
看看
listener.ora ===》伺服器偵聽服務配置
shrept.lst
tnsnames.ora ====》用戶端連接配接伺服器配置檔案 wbm01客戶使用這個檔案連接配接服務
要保證wbm01使用者能通路這個目錄:ADR_BASE = /home/oracle_11/app
3 解決步驟
====> 然後切換使用者
[[email protected] app]$ cd /home/oracle_11/app
[[email protected] app]$ pwd
/home/oracle_11/app
[[email protected] app]$ ls
admin cfgtoollogs checkpoints diag flash_recovery_area oracle oradata oradiag_oracle
[[email protected] app]$ cd admin/
-bash: cd: admin/: 權限不夠
解決如下:
root用
chomd 775 /home/oracle_11/app (家目錄)
windows下繼續
然後配置plsql或者navicat
我用的navicat,工具-》選項
然後就可以連接配接資料庫了
ok...成功
現在來配置 oracle odbc
oracle instance client 裡面 安裝路徑E:\oracle_client\instantclient_18_3預設就有
如果沒有請下載下傳 1. oracle instance client 安裝:https://www.oracle.com/technetwork/cn/database/features/instant-client/index-092699-zhs.html(注意是32位還是64位,不然不工作了)
就可以了!
一定要分請你是32位還是64位,如果不行請自行換成相應位數(win7 32/64都支援)
如果你是64位系統這個資料源ODBC
需要運作C:\Windows\SysWOW64檔案夾下的
或者控制台-》管理工具-》資料源odbc-》添加
Data Source Name ,descript随便寫
TNS service name:需要和tnsnames.ora配置的名字一樣
userid:資料庫名字(如scott等)
點選 test connection ,彈出成功連接配接即可!
ok........
搞定,bye 了個bye.... 忒麻煩了.....
轉載于:https://www.cnblogs.com/bwbfight/p/9639938.html