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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

See all articles