oracle oracle中的别名数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4422362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Alias database in oracle
提问by dbeacham
If I have an oracle 11g database set up so that I can access it with
如果我设置了一个 oracle 11g 数据库以便我可以访问它
sqlplus user/pass@localhost:1521/ora11
However, I was wondering whether it is possible to set an alias to access it via:
但是,我想知道是否可以设置别名以通过以下方式访问它:
sqlplus user/pass@ora11
I can set the oracle SID and connect through
我可以设置 oracle SID 并通过连接
export ORACLE_SID=ora11
sqlplus user/pass
However, if I have more than one database, ie ORA10 -> oracle 10 and ORA11 -> oracle 11, then I'd prefer to connect as
但是,如果我有多个数据库,即 ORA10 -> oracle 10 和 ORA11 -> oracle 11,那么我更愿意连接为
sqlplus user/pass@ORA10
sqlplus user/pass@ORA11
rather than having to type out localhost or set ORACLE_SID each time.
而不必每次都输入 localhost 或设置 ORACLE_SID。
It would also be useful to do this if I'm trying to access remote oracle databases and don't want to have to remember the IP/PORT/SID everytime I wish to connect.
如果我尝试访问远程 oracle 数据库并且不想每次希望连接时都必须记住 IP/PORT/SID,那么这样做也很有用。
回答by SimonJ
Add an entry to $ORACLE_HOME/network/admin/tnsnames.ora
for each database you want to connect to:
$ORACLE_HOME/network/admin/tnsnames.ora
为要连接的每个数据库添加一个条目:
ORA11 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ORA11) ) )
You can now connect to this database using sqlplus user/pass@ORA11
.
您现在可以使用sqlplus user/pass@ORA11
.
回答by bernd_k
On Client side you can use TNSNANES.ORA to do this. But similar to ODBC settings this defines the names only for one client. Different Clients can use different names.
在客户端,您可以使用 TNSNANES.ORA 来执行此操作。但与 ODBC 设置类似,它只为一个客户端定义名称。不同的客户端可以使用不同的名称。
回答by Bernaridho Hutabarat
I suggest this entry instead
我建议改为使用此条目
SERVICE11 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SID = INSTANCE11)
)
)
It's much better to name your instance and your service mimicking the concepts. Hence, the name SERVICE11 to represent the concept of service, and INSTANCE11 to represent the concept of instance. For service related to Oracle 10g, you can have:
最好模仿这些概念来命名您的实例和服务。因此,名称 SERVICE11 表示服务的概念,而名称 INSTANCE11 表示实例的概念。对于 Oracle 10g 相关的服务,您可以拥有:
SERVICE10 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1520))
)
(CONNECT_DATA =
(SID = INSTANCE10)
)
)
You must setup two listener, each listening to different port value. It seems to me you want to use several DBMSs. As you see, there is no database involved in the tnsnames.ora. Hence the phrase 'connect to database' is wrong.
您必须设置两个侦听器,每个侦听器侦听不同的端口值。在我看来,您想使用多个 DBMS。如您所见,tnsnames.ora 中没有涉及数据库。因此短语“连接到数据库”是错误的。
After setting up the two listeners and the related listener-config file, put entry of both services in the tnsnames.ora in your client-host. You can then
设置两个监听器和相关的监听器配置文件后,将两个服务的条目放在客户端主机的 tnsnames.ora 中。然后你可以
sqlplus username/password@service10 sqlplus username/password@service11
sqlplus 用户名/密码@service10 sqlplus 用户名/密码@service11