通过 cygwin sqlplus 连接到远程 oracle

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/299504/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:30:03  来源:igfitidea点击:

connecting to remote oracle via cygwin sqlplus

oraclecygwinsqlplus

提问by MCS

I'm trying to use cygwin sqlplus to connect to a remote oracle installation located at myserver.mycompany.com port 1530. When I try

我正在尝试使用 cygwin sqlplus 连接到位于 myserver.mycompany.com 端口 1530 的远程 oracle 安装。当我尝试时

sqlplus [email protected]:1530/orcl

I get the error:

我收到错误:

ORA-12154: TNS:could not resolve the connect identifier specified

When I set ORACLE_HOMEto /cygdrive/c/oracle/product/10.2.0/client_1, I get a different error:

当我设置ORACLE_HOME为 / 时cygdrive/c/oracle/product/10.2.0/client_1,出现不同的错误:

Error 6 initializing SQL*Plus
Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

I can telnet to the server's port 1530, and the SQL Developer installed locally is also able to connect to the database. What am I doing wrong?

我可以telnet到服务器的1530端口,本地安装的SQL Developer也可以连接数据库。我究竟做错了什么?

回答by ConcernedOfTunbridgeWells

I wasn't aware there was a native cygwin client for Oracle (correct me if I'm wrong here but I can't find any mention of it on Oracle's web site either). If you're using Cygwin with the Windows client you need to use a native windows path. It won't understand your /cygdrive path.

我不知道有一个用于 Oracle 的本地 cygwin 客户端(如果我在这里错了,请纠正我,但我在 Oracle 的网站上也找不到任何提及)。如果您将 Cygwin 与 Windows 客户端一起使用,则需要使用本机 Windows 路径。它不会理解您的 /cygdrive 路径。

However, I have used Win32 Oracle clients with cygwin and made it work - the same shell scripts would work on Cygwin, Linux and Solaris.

但是,我已经将 Win32 Oracle 客户端与 cygwin 一起使用并使其工作 - 相同的 shell 脚本可以在 Cygwin、Linux 和 Solaris 上工作。

回答by Thomas Jones-Low

There isn't a cygwin Oracle client. As above answer, use the ORACLE_HOME set to the windows path.

没有 cygwin Oracle 客户端。如上答案,使用 ORACLE_HOME 设置为 windows 路径。

For the first half of your question, try seeing what the TNS_NAMES env variable is set to, and if not set, you may need to try setting it to the correct place. Usually it defaults to %ORACLE_HOME%/network/admin/tnsnames.ora . SQL Developer keeps it's own copy of the tnsnames file, so you can't reply upon that to fix the problem.

对于问题的前半部分,请尝试查看 TNS_NAMES 环境变量设置为什么,如果未设置,您可能需要尝试将其设置为正确的位置。通常它默认为 %ORACLE_HOME%/network/admin/tnsnames.ora 。SQL Developer 保留它自己的 tnsnames 文件副本,因此您无法通过回复来解决问题。

回答by Izzy

Combining the details from the other answers (which took me a little, so I post it as separate answer instead of comments):

结合其他答案的细节(这花了我一点时间,所以我将其作为单独的答案而不是评论发布):

The $ORACLE_SIDand, if set, $TNS_ADMIN(and probably other path-related Oraclevariables) must use Windows-paths. Your Cygwin $PATHvariable should of course use the Cygwin notation (/drives/c/…). So I've included into my .bashrc:

$ORACLE_SID,如果一套,$TNS_ADMIN(可能其他路径相关的Oracle变量)必须使用Windows路径。您的 Cygwin$PATH变量当然应该使用 Cygwin 符号 ( /drives/c/…)。所以我已经包含在我的.bashrc

export ORACLE_HOME=c:\Oracle\product\12.1.0\dbhome_1
export TNS_ADMIN=d:\Oracle\TNSAdmin
export PATH=$PATH:$(cygpath -u $ORACLE_HOME)/BIN

After that, I had no more issues calling e.g. tnspingor sqlplus. As the above is just an example, you must of course adjust the paths to reflect your installation/configuration :)

在那之后,我不再有调用 egtnsping或 的问题sqlplus。由于以上只是一个示例,您当然必须调整路径以反映您的安装/配置:)

回答by user3073309

I have same error like you,

我有和你一样的错误

you should set not only ORACLE_HOMEin windows Variables,

你不仅应该ORACLE_HOME在 windows 中设置变量,

But also PATHinclude %ORACLE_HOME%\bin

但也PATH包括%ORACLE_HOME%\bin

then you can open windows cmd,

然后你可以打开windows cmd,

try sqlplus username/password@your_define_tnsname

尝试 sqlplus username/password@your_define_tnsname

if okay, then remove all ORACLE PATHsetting in cygwin, restart cygwin,try it.

如果可以,然后删除ORACLE PATHcygwin中的所有设置,重新启动cygwin,尝试一下。

if failure, should let sqlplus works well in windows cmd at first

如果失败,首先应该让 sqlplus 在 windows cmd 中运行良好

回答by MCS

NXC is right - it wasn't a cygwin client I was using, but the windows sqlplus client. I set the windows environment variables for ORACLE_HOMEand ORACLE_SIDand was then able to run sqlplus in a cygwin bash shell using the net_service_namefrom tnsnames.ora.

NXC 是对的——它不是我使用的 cygwin 客户端,而是 windows sqlplus 客户端。我为ORACLE_HOMEand设置了 windows 环境变量,ORACLE_SID然后能够使用net_service_namefrom tnsnames.ora在 cygwin bash shell 中运行 sqlplus 。

回答by Sina

The way it worked for me was to remove /cygdrive/dor /cygdrive/cand replace them with with d:/or c:/and then your sqlpluscall within cygwin session will work. The /cygdrive/DriveLetteris confusing it.

它对我有用的方法是删除/cygdrive/d/cygdrive/c替换它们,然后用d:/or替换它们,c:/然后您sqlplus在 cygwin 会话中的调用将起作用。这/cygdrive/DriveLetter是混淆它。