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

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

Jun 07, 2016 pm 05:33 PM

各种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 of this Website
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

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

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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.

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]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

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]

How do you drop a table in MySQL using the DROP TABLE statement? How do you drop a table in MySQL using the DROP TABLE statement? Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns? How do you create indexes on JSON columns? Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do you represent relationships using foreign keys? How do you represent relationships using foreign keys? Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles