解決windows7無法連接CentOS7系統中oracle問題:ORA-12514 TNS 監聽程序當前無法識別


linux開啟后終端按下面輸入(容易忘記,記錄下);

 [oracle@localhost ~]$ lsnrctl stop                #先關閉監聽服務

 [oracle@localhost ~]$ lsnrctl start                    #開啟監聽服務

 [oracle@localhost ~]$ sqlplus / as sysdba     #登入

SQL> shutdown immediate             #立即關閉數據庫服務(一般是關閉狀態)
SQL> startup                                    #開啟數據庫服務(重要,必輸)

SQL> exit                                 #退出

SQL> sqlplus scott/tiger@192.168.78.130/orcl    #連接scott用戶

SQL> select * from tab;                  #test查詢表

 

 

解決問題:ORA-12514 TNS 監聽程序當前無法識別連接描述符中請求服務

測試環境:CentOS-7 + Oracle 11g 64位

相關說明:

數據庫服務器:

Oracle11g64位軟件的安裝位置為data/oracle/product/11.2.0/db_1,數據庫名為默認的orcl,

CentOS7虛擬機的IP設置為:192.168.78.130

Windows7客戶端:

1、PLSQL安裝位置:C:\Program Files\PLSQL Developer

InstantClient存放位置:C:\Program Files\PLSQL Developer\instantclient_11_2,並創建文件network,創建文件夾admin;

2.在C:\Program Files\PLSQL Developer\instantclient_11_2\network\admin新建tnsnames.ora,用記事本編輯.


ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =
虛擬機IP)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
))

3.添加一個環境變量,名為TNS_ADMIN,值為tnsnames.ora文件所在路徑C:\Program Files\PLSQL Developer\instantclient_11_2\network\admin,plsql通過這個找到orcl連接字符串

4.添加一個環境變量NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK

5.打開PLSQL,不用登陸,工具-首選項-ORACLE-連接:


勾選檢查連接
Oracle主目錄: C:\Program Files\PLSQL Developer\instantclient_11_2
OCI庫:C:\Program Files\PLSQL Developer\instantclient_11_2\network\admin\oci.dll

 

遇到問題:

使用plsql連接數據庫服務器:“ORA-12514 TNS 監聽程序當前無法識別連接描述符中請求服務”

 

解決辦法簡述:

1.修改\data\oracle\product\11.2.0\db_1\network\admin\listener.ora中的localhost改為192.168.78.130

2.修改\data\oracle\product\11.2.0\db_1\network\admin\tnsnames.ora中的localhost 改為 192.168.78.130

3.修改后,重啟oracle,監聽,並注冊,主win7上的plsql就可以遠程連接虛擬機上的數據庫了.

 

具體操作步驟如下:

一、修改數據庫服務器中listener.ora文件內容

命令:

[oracle@localhost admin]$ vi /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
原始內容:


# listener.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/listener.ora

# Generated by Oracle configuration tools.

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

    )

  )

ADR_BASE_LISTENER = /data/oracle

 

修改為:

# listener.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /data/oracle/product/11.2.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.78.130)(PORT = 1521)))
ADR_BASE_LISTENER = /data/oracle

 


二、修改數據庫服務器中tnsnames.ora文件內容

命令:

[oracle@localhost admin]$ vi /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora

原始內容:


# tnsnames.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

    )

  )

 

修改后的內容:

# tnsnames.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

orcl =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.78.130)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SID = orcl)

    )

  )

 


三、在數據庫服務器中啟動監聽並更新注冊

1、命令:

[oracle@localhost ~]$ lsnrctl stop                #先關閉監聽服務

輸出:

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-FEB-2017 21:19:42

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.78.130)(PORT=1521)))

The command completed successfully

[oracle@localhost ~]$

 

2、命令:

[oracle@localhost ~]$ lsnrctl start                    #開啟監聽服務
輸出:


LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-FEB-2017 21:24:22

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Starting /data/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 /data/oracle/product/11.2.0/db_1/network/admin/listener.ora

Log messages written to /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521)))

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.78.130)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                19-FEB-2017 21:24:22

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.ora

Listener Log File         /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521)))

Services Summary...

Service "orcl" has 1 instance(s).

  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

[oracle@localhost ~]$

 


 

3、命令:

[oracle@localhost ~]$ sqlplus / as sysdba     #登入

輸出:

SQL*Plus: Release 11.2.0.1.0 Production on Sun Feb 19 21:27:40 2017

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>    

命令:

SQL> shutdown immediate             #立即關閉數據庫服務

輸出:

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>

 

命令:
SQL> startup                                    #開啟數據庫服務

輸出:

ORACLE instance started.

Total System Global Area 1586708480 bytes

Fixed Size                2213736 bytes

Variable Size                  939526296 bytes

Database Buffers           637534208 bytes

Redo Buffers                    7434240 bytes

Database mounted.

Database opened.

SQL>

 

命令:
SQL>
alter system register;        #注冊

輸出:

System altered.

SQL>
命令:

SQL> quit         #登出

輸出:

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@localhost ~]$


 

命令:
[oracle@localhost ~]$
lsnrctl status        #查看監聽狀態

輸出:

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-FEB-2017 21:37:20

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.78.130)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                19-FEB-2017 21:24:22

Uptime                    0 days 0 hr. 12 min. 57 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.ora

Listener Log File         /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521)))

Services Summary...

Service "orcl" has 1 instance(s).

  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

[oracle@localhost ~]$


 

四、Windows7客戶端下的測試步驟:使用plsqldev.exe測試,修改

C:\Program Files\PLSQL Developer\instantclient_11_2\network\admin \tnsnames.ora

文件,新增到虛擬機Oracle的連接內容

# tnsnames.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

CentosOracle =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.78.130)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

    )

  )

運行plsql,使用SYS用戶登錄成功(我這里使用scott用戶)

 

linux開啟后終端按下面輸入;

 [oracle@localhost ~]$ lsnrctl stop                #先關閉監聽服務

 [oracle@localhost ~]$ lsnrctl start                    #開啟監聽服務

 [oracle@localhost ~]$ sqlplus / as sysdba     #登入

SQL> shutdown immediate             #立即關閉數據庫服務(一般是關閉狀態)
SQL> startup                                    #開啟數據庫服務(重要,必輸)

SQL> exit                                 #退出

SQL> sqlplus scott/tiger@192.168.78.130/orcl    #連接scott用戶

SQL> select * from tab;                  #test查詢表


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM