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

linux開啓後終端按下面輸入(容易忘記,記錄下);mysql

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

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

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

SQL> shutdown immediate             #當即關閉數據庫服務(通常是關閉狀態)
SQL> startup                                    #開啓數據庫服務(重要,必輸)服務器

SQL> exit                                 #退出oracle

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

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

 

 

解決問題: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就能夠遠程鏈接虛擬機上的數據庫了.

 

具體操做步驟以下:

1、修改數據庫服務器中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

 


2、修改數據庫服務器中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)

    )

  )

 


3、在數據庫服務器中啓動監聽並更新註冊

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 ~]$


 

4、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查詢表

相關文章
相關標籤/搜索