实验目的:在虚拟机中用sqlplus工具访问真实机的数据库;

实验环境:

真实机(windows系统,数据库服务名 orcl):

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE    10.2.0.3.0      Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production

虚拟机(linux系统,数据库服务名 yjgocp):

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

sqlplus登录本地及远程数据库的方式有:

sqlplus username/password

sqlplususername/password@net_service_name

sqlplus  username/password assysdba

sqlplususername/password@//host:port/sid

在虚拟机上操作,直接链接真实机数据库

[oracle@localhost ~]$ sqlplusscott/tiger@orcl

SQL*Plus: Release 11.2.0.1.0 Production onSun Jul 28 13:40:38 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

ERROR:

ORA-12154: TNS:could not resolve theconnect identifier specified

说明链接信息配置有问题,查看本地环境变量及查找本地tnsname.ora

[oracle@localhost ~]$ more .bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startupprograms

PATH=$PATH:$HOME/bin

export ORACLE_BASE=/u01/app/oracle

exportORACLE_HOME=/u01/app/oracle/product/11g

export ORACLE_SID=yjgocp

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

export PATH=$ORACLE_HOME/bin:$PATH

[root@localhost script]#find / -name tnsname*

/u01/app/oracle/product/11g/inventory/Templates/hs/admin/tnsnames.ora.sample

/u01/app/oracle/product/11g/network/admin/samples/tnsnames.ora

/u01/app/oracle/product/11g/hs/admin/tnsnames.ora.sample

TNS_ADMIN

This variable  TNS_ADMIN specifies the user ID of the OracleNet Services configuration files, for example, LISTENER.ORATNSNAMES.ORA and SQLNET.ORA. If TNS_ADMIN is not defined, then the configuration files are searched underthe local user ID with the prefix NETWORK.ADMIN.

环境变量里面没有设置该值,说明oracle 会到默认的network/admin/下查找LISTENER.ORATNSNAMES.ORA and SQLNET.ORA文件,如果想链接远程数据库,那么需要在该位置创建一个TNSNAME.ORA文件,并把远程的链接信息配置到该文件中;

 

经过刚才查找得之/u01/app/oracle/product/11g/network/admin/samples/tnsnames.ora把该文件拷贝到/u01/app/oracle/product/11g/network/admin/目录下一份,

然后添加远程数据库的链接信息:

[oracle@localhost admin]$ more tnsnames.ora

# This file contains the syntax informationfor

# the entries to be put in any tnsnames.orafile

# The entries in this file are need based.

# There are no defaults for entries in thisfile

# that Sqlnet/Net3 use that need to beoverridden

#

# Typically you could have two tnsnames.orafiles

# in the system, one that is set for theentire system

# and is called the system tnsnames.orafile, and a

# second file that is used by each userlocally so that

# he can override the definitions dictatedby the system

# tnsnames.ora file.

# The entries in tnsnames.ora are analternative to using

# the names server with the onames adapter.

# They are a collection of aliases for theaddresses that

# the listener(s) is(are) listening for adatabase or

# several databases.

# The following is the general syntax forany entry in

# a tnsnames.ora file. There could beseveral such entries

# tailored to the user's needs.

#下面红色字体是添加的远程链接信息;其余代码是该文件原有的代码;

ORCL =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.100)(PORT = 1521))

(CONNECT_DATA =

(SERVICE_NAME = orcl)

)

)

<alias>= [ (DESCRIPTION_LIST =  # Optional depending on whether u have

# one or moredescriptions

# If there isjust one description, unnecessary

]

(DESCRIPTION=

[ (SDU=2048) ]      # Optional,defaults to 2048

# Can take values between 512 and 32K

[ (ADDRESS_LIST=    # Optionaldepending on whether u have

# one or moreaddresses

# If there isjust one address, unnecessary ]

(ADDRESS=

[(COMMUNITY=<community_name>) ]

(PROTOCOL=tcp)

(HOST=<hostname>)

(PORT=<portnumber (1521 is astandard port used)>)

)

[ (ADDRESS=

(PROTOCOL=ipc)

(KEY=<ipckey (PNPKEY is astandard key used)>)

)

]

[ (ADDRESS=

[(COMMUNITY=<community_name>) ]

(PROTOCOL=decnet)

(NODE=<nodename>)

(OBJECT=<objectname>)

)

]

... # More addresses

[ ) ] # Optional depending on whether ADDRESS_LIST is used or not

[ (CONNECT_DATA=

(SID=<oracle_sid>)

[(GLOBAL_NAME=<global_database_name>) ]

)

]

[ (SOURCE_ROUTE=yes) ]

)

(DESCRIPTION=

[ (SDU=2048) ]      # Optional,defaults to 2048

# Can takevalues between 512 and 32K

[ (ADDRESS_LIST= ]  # Optionaldepending on whether u have more

# than oneaddress or not

# If there is justone address, unnecessary

(ADDRESS

[(COMMUNITY=<community_name>) ]

(PROTOCOL=tcp)

(HOST=<hostname>)

(PORT=<portnumber (1521 is astandard port used)>)

)

[ (ADDRESS=

(PROTOCOL=ipc)

(KEY=<ipckey (PNPKEY is astandard key used)>)

)

]

...               # More addresses

[ ) ]               # Optionaldepending on whether ADDRESS_LIST

# is being used

[ (CONNECT_DATA=

(SID=<oracle_sid>)

[(GLOBAL_NAME=<global_database_name>) ]

)

]

[ (SOURCE_ROUTE=yes) ]

)

[ (CONNECT_DATA=

(SID=<oracle_sid>)

[(GLOBAL_NAME=<global_database_name>) ]

)

]

...   # More descriptions

[ ) ]   # Optional depending onwhether DESCRIPTION_LIST is used or not

然后尝试链接

[oracle@localhost admin]$ sqlplusscott/tiger@orcl

SQL*Plus: Release 11.2.0.1.0 Production onSun Jul 28 13:59:59 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

ERROR:

ORA-12541: TNS:nolistener

提示没有监听,这个时候查看远程数据库,监听已经启动;于是就把链接信息里的HOST信息又远程主机IP改为了主机名(由HOST = 192.168.1.100改为

HOST = 4728tef987uid34)

[oracle@localhost admin]$ sqlplusscott/tiger@orcl

SQL*Plus: Release 11.2.0.1.0 Production onSun Jul 28 14:02:38 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 10g Enterprise EditionRelease 10.2.0.3.0 - Production

With the Partitioning, OLAP and Data Miningoptions

Ok 链接成功;

另外用下面的方法也可以在没有配置tnsname.ora的情况下访问;

[oracle@localhost ~]$ sqlplus scott/tiger@//192.168.1.100/orcl

SQL*Plus: Release 11.2.0.1.0 Production onSun Jul 28 13:45:43 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 10g Enterprise EditionRelease 10.2.0.3.0 - Production

With the Partitioning, OLAP and Data Miningoptions

[oracle@localhost ~]$ sqlplus scott/tiger@//192.168.1.100/orcl

SQL*Plus: Release 11.2.0.1.0 Production onSun Jul 28 13:45:43 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 10g Enterprise EditionRelease 10.2.0.3.0 - Production

With the Partitioning, OLAP and Data Miningoptions

sqlplus 链接数据库的更多相关文章

  1. sqlplus链接数据库报ORA-09925: Unable to create audit trail file

    [localhost.localdomain]:[/oracle11/app/oracle11/product/11.2.0/dbhome_1/dbs]$ sqlplus / as sysdba SQ ...

  2. PHP学习-链接数据库

    链接数据库文件:conn.php <?php $conn = mysql_connect("localhost:3306","root","us ...

  3. PHP 链接数据库1(连接数据库&简单的登录注册)

    对 解析变量的理解 数据库的名称和表的名称不能重复 从结果中取出的数据   都是以数组的形式取出的 1.PHP查询数据库中的某条信息 //PHP链接数据库 /*1.造链接对象 IP地址 用户名 密码 ...

  4. JDBC的使用(一):引用外部jar;代码链接数据库

    一:引用外部jar 1.首先不jar文件放到项目下: 2.在Eclipse中,右键相应的项目--构建路径--配置构建路径--库--添加外部jar:选中-打开-应用-确定. 二:代码链接数据库 1.加载 ...

  5. Connect to Database Using Custom params链接数据库配置参数说明

    使用RF的关键字Connect to Database Using Custom params链接数据库,对应的参数说明: a)     第一个参数我使用的是cx_Oracle,就写这个 b)     ...

  6. php链接数据库

      1:找到 ySQL服务器 $conn = mysql_connect("localhost","","") or die("链 ...

  7. 安装vs2013以后,链接数据库总是报内存损坏,无法写入的错误

    安装vs2013以后,链接数据库总是报内存损坏,无法写入的错误 这个错误几个月以前解决过一次,但是到又碰到的时候,竟然完全忘记当时怎么解决的了, 看来上了年纪记忆真是越来越不行了... 解决方案很简单 ...

  8. jsp链接数据库

    数据库表代码: /*Navicat MySQL Data Transfer Source Server : localhost_3306Source Server Version : 50528Sou ...

  9. 本地开发 localhost链接数据库比127.0.0.1慢

    自己手写一段代码的时候发现一个问题  链接数据库的时候 用 127.0.0.1比localhost明显的快,localhost要等一下才会有响应 而127.0.0.1就是瞬间响应.一番排查,发现了一个 ...

随机推荐

  1. python 3.6 import pymysql错误

    在3.x之后可以用pymysql来代替之前的mysqldb模块. 首先安装pip: 终端命令: easy_install pip 随后成功安装pip 继续输入命令 pipinstall PyMySQL ...

  2. Unity轻量级依赖注入容器

    一.前言 Unity是一个轻量级的可扩展的依赖注入容器,支持构造函数,属性和方法调用注入.在Nuget里安装unity

  3. CSS 设计彻底研究(五)文字与图像

    第五章 文字与图像 5.1.2 设置字体 通过font-family属性设置字体.可以声明多种字体,字体之间用逗号分隔开.如一些字体名称中间有空格,需用双引号将其引起来,使浏览器知道这是一种字体的名称 ...

  4. CSS 设计彻底研究(三)深入理解盒子模型

    第三章 深入理解盒子模型 盒子模型是CSS控制页面的基础.需要清楚“盒子”的含义是什么,以及盒子的组成.此外,应该理解DOM的基本概念,以及DOM树是如何与一个HTML文档对应的,在此基础上充分理解“ ...

  5. 被sjy带刷题#1

        笔记[问题描述]给定一个长度为m的序列a,下标编号为1~m.序列的每个元素都是1~n的整数.定义序列的代价为 你现在可以选择两个数x和y,并将序列a中所有的x改成y.x可以与y相等.请求出序列 ...

  6. PHP判断访客是否移动端浏览器访问

    今天要给大家分享一段PHP代码,该代码的功能是用来判断访客是否移动端浏览器访问,该功能的实现思路是通过HTTP_X_WAP_PROFILE. HTTP_VIA.HTTP_USER_AGENT等信息来判 ...

  7. iOS开发之网络篇-各种网络状态码

    1xx消息 这一类型的状态码,代表请求已被接受,需要继续处理.这类响应是临时响应,只包含状态行和某些可选的响应头信息,并以空行结束.由于HTTP/1.0协议中没有定义任何1xx状态码,所以除非在某些试 ...

  8. mysql null值转换

    1.如果为空返回0 select ifnull(null,0) 2.如果为空返回0,否则返回1 select if(isnull(col),0,1) as col.

  9. NOI十连测 第四测 T2

    思路:线段树套可持久化treap,可持久化treap我还是第一次听说.. 改题的时候没看数据范围..乱开数组T_T #include<algorithm> #include<cstd ...

  10. T-SQL 基于列的逻辑表达式 (CASE)

    CASE简介 基于列的逻辑表达式,其实就是CASE表达式.可以用在SELECT,UPDATE,DELETE,SET以及IN,WHERE,ORDER BY和HAVING子句之后.由于这里讲的是T-SQL ...