search
HomeDatabaseMysql Tutorial各种TNS报错总结--监听器及tnsnames.ora配置文件各种出错总结

各种TNS报错总结--监听器及tnsnames.ora配置文件各种出错总结

本地命名的配置:.本地名可以用简单的名称访问到所需的数据库或服务器所需的信息,而这些信息保存到了tnsnames.ora中.

LOCALNAME: 本地名称
ADDRESS: 服务器地址
PROTOCOL: 使用协议
HOST: IP地址
PORT: 监听端口
SERVICE_NAME: 数据库服务名称
首先要保证tnsnames.ora文件中的格式正确,如=号、空格、括号之类基本格式不出错
这个可以参考我的一篇tnsnames.ora各种模板:

当我们发出一条命令:sqlplus bys/bys@test时,连接到数据库大致经过以下步骤:

1.首先在sqlplus程序的相关目录中查找tnsnames.ora

2.在tnsnames.ora中查找test=开头的字符串

3.根据tnsnames.ora中查找test=字符串中的:PROTOCOL = TCP)(HOST = 192.168.1.211) 这一句,查询相应的HOST,如是IP,则直接访问;如是域名,需要解析为IP

4.当可以与HOST =中描述的主机通讯后,再根据(PORT = 1521)这一句中的描述,在主机的1521这一端口使用TCP协议进行连接。

5.如果以上连接成功,则已经连接到数据库监听器。此时tnsnames.ora中查找test=字符串中的:SERVICE_NAME = bys1,这一句则再次指定了要连接到监听器的bys1服务上

6.如果以上连接成功,已经连接到监听器的bys1服务,则会根据监听器中服务所对应的实例,来连接到具体的实例。(在tnsnames.ora的test=字符串中也可以在SERVICE_NAME =这一句下面再指定具体实例--我实验中未指定;如不指定,则由监听器来分配;如监听器中同一服务下有多个实例(如RAC),由监听器来进行动态均衡分配连接)。

7.如果以上连接成功,,则已经连接到实例。接下来就由数据库来验证用户名、密码的正确性了。

本篇的实验即使遵循以上的sqlplus bys/bys@test连接到数据库的步骤来对每一步进行错误演示

关于连接数据库的语句:sqlplus bys/bys@192.168.1.211:1521/bys1 这种是不使用tnsnames.ora文件。连接到192.168.1.211主机的1521端口的bys1服务上。 关于SQLPLUS连接数据库的写法,更详细见:

实验环境:LINUX--OLE 5.8;Oracle -Oracle Database 11g Enterprise Edition Release 11.2.0.1.

##################################################################################

1.tnsnames.ora文件不存在。此时使用本地名来连接是不行的。

测试时:
TNSPING报错为:TNS-03505: Failed to resolve name
SQLPLUS报错为:ORA-12154: TNS:could not resolve the connect identifier specified

实验数据

[oracle@bys001 admin]$ ls
listener.bak samples tnsnames.ora
listener.ora shrept.lst
[oracle@bys001 admin]$ mv tnsnames.ora tnsnames.oraa
[oracle@bys001 admin]$ tnsping bys1
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 08-NOV-2013 09:24:18
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
TNS-03505: Failed to resolve name
[oracle@bys001 admin]$ sqlplus bys/bys@bys1
SQL*Plus: Release 11.2.0.1.0 Production on Fri Nov 8 09:25:12 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

##################################################################################

2.tnsnames.ora 中test本地名对应的字段描述格式正确,数据库监听开启。但是使用TNSPING或SQLPLUS时所用的本地名不对

(本地名指的是tnsnames.ora 中的描述字段:

test =

(DESCRIPTION = 这里;也即SQLPLUS BYS/BYS@TEST这里的TEST)

测试时:
TNSPING报错为:TNS-03505: Failed to resolve name
SQLPLUS报错为:ORA-12154: TNS:could not resolve the connect identifier specified
实验数据:
[oracle@bys001 admin]$ tnsping hello
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 07-NOV-2013 23:41:29
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:

TNS-03505: Failed to resolve name
[oracle@bys001 admin]$ sqlplus bys/bys@hello
SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 7 23:42:36 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
#########################################################################################################

3.tnsnames.ora 中test本地名对应的字段描述格式正确,数据库监听开启。但是tnsnames.ora 中HOST = 字段指定的IP不存在或无法PING通。

测试时:

TNSPING和SQLPLUS报错均为: TNS-12543: TNS:destination host unreachable

实验数据:

[oracle@bys001 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
bys1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.211)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bys1)
)
)
test =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.222)(PORT = 1521)) 手动将HOST中的IP改为一个不存在的IP即可
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bys1)
)
)
[oracle@bys001 ~]$ ping 192.168.1.222
PING 192.168.1.222 (192.168.1.222) 56(84) bytes of data.
From 192.168.1.211 icmp_seq=2 Destination Host Unreachable
From 192.168.1.211 icmp_seq=3 Destination Host Unreachable
[oracle@bys001 admin]$ tnsping test
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 07-NOV-2013 23:08:12
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.222)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = bys1)))
TNS-12543: TNS:destination host unreachable
[oracle@bys001 admin]$ sqlplus bys/bys@test
SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 7 23:08:21 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ERROR:
ORA-12543: TNS:destination host unreachable

更多详情见请继续阅读下一页的精彩内容

相关阅读:

Oracle数据库中listener.ora sqlnet.ora tnsnames.ora的区别

Oracle RAC 下非缺省端口监听配置(listener.ora tnsnames.ora)

Oracle RAC 监听配置 (listener.ora tnsnames.ora)

Oracle: listener.ora 、sqlnet.ora 、tnsnames.ora的配置及例子

Oracle本地命名服务tnsnames.ora配置

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to solve the problem of mysql cannot open shared libraryHow to solve the problem of mysql cannot open shared libraryMar 04, 2025 pm 04:01 PM

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

Reduce the use of MySQL memory in DockerReduce the use of MySQL memory in DockerMar 04, 2025 pm 03:52 PM

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Run MySQl in Linux (with/without podman container with phpmyadmin)Run MySQl in Linux (with/without podman container with phpmyadmin)Mar 04, 2025 pm 03:54 PM

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

What is SQLite? Comprehensive overviewWhat is SQLite? Comprehensive overviewMar 04, 2025 pm 03:55 PM

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Running multiple MySQL versions on MacOS: A step-by-step guideRunning multiple MySQL versions on MacOS: A step-by-step guideMar 04, 2025 pm 03:49 PM

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.