oracle安装目录

D:\u01

前言

客户端(IP01)需要访问服务端(IP02)的Oracle库ORCL。
pl/sql 连接时报错ORA-12541:TNS:no listener

解决方法

步骤一:配置客户端tnsnames.ora

D:\u01\app\oracle\product\19.3.0\network\admin\tnsnames.ora

HOST要为正确的IP地址

# tnsnames.ora Network Configuration File: D:\u01\app\oracle\product\19.3.0\NETWORK\ADMIN\tnsnames.ora# Generated by Oracle configuration tools.LISTENER_ORCL =(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.61.232)(PORT = 1521))ORACLR_CONNECTION_DATA =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)))(CONNECT_DATA =(SID = CLRExtProc)(PRESENTATION = RO)))ORCL =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.61.232)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)))

步骤二:配置服务端listener.ora

D:\u01\app\oracle\product\19.3.0\network\admin\listener.ora

同样的HOST要为正确的IP地址

# listener.ora Network Configuration File: D:\u01\app\oracle\product\19.3.0\NETWORK\ADMIN\listener.ora# Generated by Oracle configuration tools.SID_LIST_LISTENER =(SID_LIST =(SID_DESC =(SID_NAME = CLRExtProc)(ORACLE_HOME = D:\u01\app\oracle\product\19.3.0)(PROGRAM = extproc)(ENVS = "EXTPROC_DLLS=ONLY:D:\u01\app\oracle\product\19.3.0\bin\oraclr19.dll"))(SID_DESC =(SID_NAME = CLRExtProc)(ORACLE_HOME = D:\u01\app\oracle\product\19.3.0)(PROGRAM = extproc)(ENVS = "EXTPROC_DLLS=ONLY:D:\u01\app\oracle\product\19.3.0\bin\oraclr19.dll")))LISTENER =(DESCRIPTION_LIST =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.61.232)(PORT = 1521))(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))))

还有一种办法就是用hosts文件的方式

C:\windows\system32\drivers\etc\hosts文件x.x.x.x HOSTNAME

最后重启服务

步骤三:重启一下监听:lsnrctl stoplsnrctl start

cmd命令

lsnrctl stoplsnrctl start重启监听

PS:附加环境变量配置