当一个数据库上面有多个Instance时,连接Oracle就需要注意了。在单instance的情况下,由于设定了ORACLE_SID,所以用sqlplus进行连接的时候默认会连接到环境变量中指定的instance, 但是如果需要连接另外一个instance的时候,就需要显示的指定了。连接的方式一般来讲有两种方法:
1、手动export环境变量
导出之前的环境变量
oracle@b2b_plat_13619:/home/oracle>
env | grep ORA
ORACLE_SID=moree
ORACLE_BASE=/opt/oracle
ORA_ENCRYPT_LOGIN=true
ORA_NLS33=/opt/oracle/products/9.2.0/ocommon/nls/admin/data
ORACLE_HOME=/opt/oracle/products/9.2.0
ORACLE_SID=moree
ORACLE_BASE=/opt/oracle
ORA_ENCRYPT_LOGIN=true
ORA_NLS33=/opt/oracle/products/9.2.0/ocommon/nls/admin/data
ORACLE_HOME=/opt/oracle/products/9.2.0
显示的导出环境变量
oracle@b2b_plat_13619:/home/oracle>
export ORACLE_SID=otter
oracle@b2b_plat_13619:/home/oracle>env | grep ORA
ORACLE_SID=otter
ORACLE_BASE=/opt/oracle
ORA_ENCRYPT_LOGIN=true
ORA_NLS33=/opt/oracle/products/9.2.0/ocommon/nls/admin/data
ORACLE_HOME=/opt/oracle/products/9.2.0
oracle@b2b_plat_13619:/home/oracle>env | grep ORA
ORACLE_SID=otter
ORACLE_BASE=/opt/oracle
ORA_ENCRYPT_LOGIN=true
ORA_NLS33=/opt/oracle/products/9.2.0/ocommon/nls/admin/data
ORACLE_HOME=/opt/oracle/products/9.2.0
此时直接用sqlplus连接oracle时,就是连接到otter实例了。
2、修改tnsnames.ora文件
OTTER.
DB.ALIBABA.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = b2b_plat_13619)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = otter)
)
)
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = b2b_plat_13619)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = otter)
)
)
【注意】域名的设置是在sqlnet.ora文件中,
NAMES.DEFAULT_DOMAIN = db.alibaba.com
oracle@b2b_plat_13619:/home/oracle>more /home/oracle/products/9.2.0/network/admin/
sqlnet.ora
# SQLNET.ORA Network Configuration File: /opt/oracle/products/9.2.0/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
MES.DIRECTORY_PATH= (TNSNAMES,HOSTNAME)
NAMES.DEFAULT_DOMAIN = db.alibaba.com
# SQLNET.ORA Network Configuration File: /opt/oracle/products/9.2.0/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
MES.DIRECTORY_PATH= (TNSNAMES,HOSTNAME)
NAMES.DEFAULT_DOMAIN = db.alibaba.com
使用sqlplus连接数据库:
连接数据库时可以指定域名,也可以不指定域名都是可以的
@>conn retl/retl@OTTER.DB.ALIBABA.COM
Connected.
Connected.
@>conn retl/retl@OTTER
Connected.
Connected.
本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/291496,如需转载请自行联系原作者